home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume2 / ditdvi < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  52.6 KB

  1. From: ken@rochester.UUCP (Ken Yap)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i101: ditroff to DVI filter - ditdvi
  4. Message-ID: <8804202327.AA29681@cursa.cs.rochester.edu>
  5. Date: 20 Apr 88 23:27:23 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. comp.sources.misc: Volume 2, Issue 101
  9. Submitted-By: "Ken Yap" <ken@rochester.UUCP>
  10. Archive-Name: ditdvi
  11.  
  12. I'm sick of this kid. Out the door it goes.
  13.  
  14.     Ken
  15.  
  16. #!/bin/sh
  17. # This is a shell archive, meaning:
  18. # 1. Remove everything above the #!/bin/sh line.
  19. # 2. Save the resulting text in a file.
  20. # 3. Execute the file with /bin/sh (not csh) to create the files:
  21. #    README
  22. #    Makefile
  23. #    cmbx10
  24. #    cmmi10
  25. #    cmr10
  26. #    cmss10
  27. #    cmssbx10
  28. #    cmssi10
  29. #    cmsy10
  30. #    cmti10
  31. #    cmtt10
  32. #    ditdvi.1
  33. #    ditdvi.c
  34. #    ditdvi.h
  35. #    dvi.c
  36. #    dvi.h
  37. #    fontfile.c
  38. #    getspecials
  39. #    reader.c
  40. #    tfm2desc.1
  41. #    tfm2desc.c
  42. # This archive created: Tue Apr 19 19:06:41 1988
  43. # By:    Ken Yap ()
  44. export PATH; PATH=/bin:$PATH
  45. echo shar: extracting "'README'" '(4022 characters)'
  46. if test -f 'README'
  47. then
  48.     echo shar: over-writing existing file "'README'"
  49. fi
  50. cat << \SHAR_EOF > 'README'
  51. These are the sources for a ditroff (not troff) to TeX DVI converter.
  52. I wrote this on a lark and to learn DVI format. Some reasons why you
  53. may want this:
  54.  
  55. + Your high resolution printer accepts DVI but you don't have a ditroff
  56. filter for it.
  57.  
  58. + You want to access the wide range of characters in TeX fonts.
  59.  
  60. + You want to create weird and wonderful fonts for ditroff with METAFONT.
  61.  
  62. + You have only a DVI previewer.
  63.  
  64. + You want to standardize on one type of output.
  65.  
  66. + You want to give the operator of a non-Unix machine a fit by printing
  67. a Unix man page on the DVI printer.
  68.  
  69. + (Put your own reason here.)
  70.  
  71. It works pretty well and I have printed tens of pages of documentation
  72. with it.
  73.  
  74. You may do whatever you like with the source, except make money out of
  75. it (because I gave it to you for free to begin with).  Do leave my name
  76. in this documentation.
  77.  
  78. How it works:
  79.  
  80. Edit Makefile to specify where the TeX tfm files live and where ditroff
  81. expects to find the binary tables.
  82.  
  83. The files cm* define the fonts of a virtual printer called dvi.  You
  84. run the program tfm2desc to generate font tables in the files R, I, B,
  85. etc. See the man page for tfm2desc and the Makefile entry for metrics
  86. for flags to tfm2desc.  Make all, then run makedev (in your ditroff
  87. distribution, not supplied here) or a PD version of that to make binary
  88. font tables for ditroff.  Install these binary tables in a subdirectory
  89. called devdvi near where ditroff expects to find other tables.
  90.  
  91. If you want to add fonts, make up more cm* description files and edit
  92. Makefile to add the font names. You have to estimate the spacewidth
  93. passed to tfm2desc. I use half of the width of a digit.  cmss isn't
  94. really Helvetica, just sort of sans serif.
  95.  
  96. The resolution of this virtual printer is irrelevant so I've set it at
  97. 576 (8*72). You can change this in the Makefile.  You must choose a
  98. unitwidth such that all the character widths are under 256, because
  99. ditroff stores the widths in single bytes. The roundoff error will be
  100. minimized if the widths are as large as possible.  Fortunately for
  101. ditroff, the resolution of DVI files is much higher than anything
  102. ditroff can comprehend. (1 / 2^16 of a point, if you are curious.)
  103.  
  104. Sizes 10 and below are translated to TeX fonts at their respective
  105. design size. Above that, magnification is used. Hence the code to
  106. translate size to magnification in reader.c. Most TeX fonts follow this
  107. pattern of availability. Unfortunately the SIZES macro in the Makefile
  108. isn't all you have to change if you want to add more sizes. You also
  109. have to edit the switch statement in reader.c and make sure you have
  110. the fonts in the right design size and magnification.
  111.  
  112. Note that if you don't have a font of the right size, you don't find
  113. out until you try to print the DVI file, or convert it to your printer
  114. language.
  115.  
  116. There is no room for the spaces or rule characters in the TeX character
  117. set, so I've put spaces at 0200 and the rule at 0201. The constant 0201
  118. is hacked into tfm2desc and ditdvi. Sorry.
  119.  
  120. I haven't tried out how well extended parens, brackets and braces are
  121. drawn with eqn.
  122.  
  123. Drawing functions are not implemented. You can translate these to tpic
  124. generated \specials. I'm too lazy.
  125.  
  126. Some special characters must be provided to ditroff or it will have a
  127. fit or at least drop your characters silently.  These include hyphen
  128. (hy), mathtimes (**), vertical bar (bv), the spaces and rule. The whole
  129. sordid story can be read in "Adventures with Typesetter Independent
  130. Troff" by Moore and Kahrs, TR 159, June 1985, Computer Science Dept.,
  131. U. of Rochester.  It's fascinating how much knowledge of the special
  132. fonts is still hardwired into ditroff.
  133.  
  134. There is one potential bug in fontfile.c. A pointer to a table of
  135. shorts may be non-word aligned. Some machines don't like this.  You
  136. need to do a block copy to malloc'ed memory. Again, I was lazy.
  137.  
  138. If you have old troff, my condolences. Have fun.
  139.  
  140. You can send me bug reports but I'm not too motivated to do much about
  141. them.
  142.  
  143.     Ken Yap
  144.     ken@cs.rochester.edu
  145.     April 1988
  146. SHAR_EOF
  147. if test 4022 -ne "`wc -c 'README'`"
  148. then
  149.     echo shar: error transmitting "'README'" '(should have been 4022 characters)'
  150. fi
  151. echo shar: extracting "'Makefile'" '(1609 characters)'
  152. if test -f 'Makefile'
  153. then
  154.     echo shar: over-writing existing file "'Makefile'"
  155. fi
  156. cat << \SHAR_EOF > 'Makefile'
  157. CFLAGS        = -g -DRESOLUTION=$(RESOLUTION) -DFONTDIR=\"$(FONTDIR)\" -DTEXFONT=\"$(TEXFONT)\"
  158.  
  159. RESOLUTION    = 576
  160. UNITWIDTH    = 24
  161. FONTS        = R I B H HB HI C M S
  162. SIZES        = 5 6 7 8 9 10 11 12 14 17 24 25 0
  163.  
  164. FONTDIR        = /u/ken/lib/ditdvi
  165. TEXFONT        = /usr/lib/tex/fonts/
  166.  
  167. all:        tfm2desc ditdvi metrics descfile
  168.  
  169. ditdvi:        ditdvi.o reader.o dvi.o fontfile.o
  170.         $(CC) $(LDFLAGS) $(CFLAGS) -o $@ ditdvi.o reader.o dvi.o fontfile.o
  171.  
  172. ditdvi.o:    ditdvi.c ditdvi.h
  173.  
  174. reader.o:    reader.c ditdvi.h
  175.  
  176. dvi.o:        dvi.c dvi.h
  177.  
  178. fontfile.o:    fontfile.c ditdvi.h
  179.  
  180. tfm2desc.o:    tfm2desc.c
  181.  
  182. tfm2desc:    tfm2desc.o
  183.         $(CC) $(LDFLAGS) $(CFLAGS) -o $@ tfm2desc.o
  184.  
  185. metrics:    tfm2desc
  186.         tfm2desc -d$(UNITWIDTH) -s48 cmr10 > R
  187.         tfm2desc -d$(UNITWIDTH) -s55 cmbx10 > B
  188.         tfm2desc -d$(UNITWIDTH) -s49 cmti10 > I
  189.         tfm2desc -d$(UNITWIDTH) -s48 cmss10 > H
  190.         tfm2desc -d$(UNITWIDTH) -s53 cmssbx10 > HB
  191.         tfm2desc -d$(UNITWIDTH) -s49 cmssi10 > HI
  192.         tfm2desc -d$(UNITWIDTH) -s101 cmtt10 m > C
  193.         tfm2desc -d$(UNITWIDTH) -s48 cmmi10 s > M
  194.         tfm2desc -d$(UNITWIDTH) -s48 cmsy10 s > S
  195.  
  196. #
  197. #    mc is a local program that does multicolumn
  198. #    you can figure out something with awk, I'm sure
  199. #
  200. descfile:
  201.         echo '# ditroff device description for TeX' > DESC
  202.         echo fonts `echo $(FONTS) | wc -w` $(FONTS) >> DESC
  203.         echo sizes $(SIZES) >> DESC
  204.         echo res $(RESOLUTION) >> DESC
  205.         echo hor 1 >> DESC
  206.         echo vert 1 >> DESC
  207.         echo unitwidth $(UNITWIDTH) >> DESC
  208.         echo paperwidth `expr $(RESOLUTION) \* 17 / 2` >> DESC
  209.         echo paperlength `expr $(RESOLUTION) \* 11` >> DESC
  210.         echo charset >> DESC
  211.         getspecials | mc >> DESC
  212.  
  213. backup:
  214.         cd ..; ctar Ditdvi | rsh can 'cd Src/Text/TeX; vtar'
  215. SHAR_EOF
  216. if test 1609 -ne "`wc -c 'Makefile'`"
  217. then
  218.     echo shar: error transmitting "'Makefile'" '(should have been 1609 characters)'
  219. fi
  220. echo shar: extracting "'cmbx10'" '(874 characters)'
  221. if test -f 'cmbx10'
  222. then
  223.     echo shar: over-writing existing file "'cmbx10'"
  224. fi
  225. cat << \SHAR_EOF > 'cmbx10'
  226. B
  227. 000    *G
  228. 001    *D
  229. 002    *H
  230. 003    *L
  231. 004    *C
  232. 005    *P
  233. 006    *S
  234. 007    *U
  235. 010    *F
  236. 011    *Q
  237. 012    *W
  238. 013    ff
  239. 014    fi
  240. 015    fl
  241. 016    Fi
  242. 017    Fl
  243. 020    ui
  244. 021    uj
  245. 022    \`
  246. 022    ga
  247. 023    \'
  248. 023    aa
  249. 024    hc
  250. 025    be
  251. 026    ma
  252. 027    ri
  253. 030    cd
  254. 031    ss
  255. 032    ae
  256. 033    oe
  257. 034    o/
  258. 035    AE
  259. 036    OE
  260. 037    O/
  261. 041    !
  262. 042    "
  263. 042    rq
  264. 043    #
  265. 044    $
  266. 045    %
  267. 046    &
  268. 047    '
  269. 050    (
  270. 051    )
  271. 052    *
  272. 053    +
  273. 054    ,
  274. 055    -
  275. 055    \-
  276. 055    hy
  277. 056    .
  278. 057    /
  279. 060    0
  280. 061    1
  281. 062    2
  282. 063    3
  283. 064    4
  284. 065    5
  285. 066    6
  286. 067    7
  287. 070    8
  288. 071    9
  289. 072    :
  290. 073    ;
  291. 074    !!
  292. 074    I!
  293. 075    =
  294. 076    I?
  295. 077    ?
  296. 100    @
  297. 101    A
  298. 102    B
  299. 103    C
  300. 104    D
  301. 105    E
  302. 106    F
  303. 107    G
  304. 110    H
  305. 111    I
  306. 112    J
  307. 113    K
  308. 114    L
  309. 115    M
  310. 116    N
  311. 117    O
  312. 120    P
  313. 121    Q
  314. 122    R
  315. 123    S
  316. 124    T
  317. 125    U
  318. 126    V
  319. 127    W
  320. 130    X
  321. 131    Y
  322. 132    Z
  323. 133    [
  324. 134    lq
  325. 135    ]
  326. 136    ^
  327. 137    dt
  328. 140    `
  329. 141    a
  330. 142    b
  331. 143    c
  332. 144    d
  333. 145    e
  334. 146    f
  335. 147    g
  336. 150    h
  337. 151    i
  338. 152    j
  339. 153    k
  340. 154    l
  341. 155    m
  342. 156    n
  343. 157    o
  344. 160    p
  345. 161    q
  346. 162    r
  347. 163    s
  348. 164    t
  349. 165    u
  350. 166    v
  351. 167    w
  352. 170    x
  353. 171    y
  354. 172    z
  355. 173    en
  356. 174    em
  357. 175    ''
  358. 176    ~
  359. 177    ..
  360. 177    um
  361. 200    \&
  362. 200    \|
  363. 200    \^
  364. SHAR_EOF
  365. if test 874 -ne "`wc -c 'cmbx10'`"
  366. then
  367.     echo shar: error transmitting "'cmbx10'" '(should have been 874 characters)'
  368. fi
  369. echo shar: extracting "'cmmi10'" '(766 characters)'
  370. if test -f 'cmmi10'
  371. then
  372.     echo shar: over-writing existing file "'cmmi10'"
  373. fi
  374. cat << \SHAR_EOF > 'cmmi10'
  375. M
  376. 000    *G
  377. 001    *D
  378. 002    *H
  379. 003    *L
  380. 004    *C
  381. 005    *P
  382. 006    *S
  383. 007    *U
  384. 010    *F
  385. 011    *Q
  386. 012    *W
  387. 013    *a
  388. 014    *b
  389. 015    *g
  390. 016    *d
  391. 017    *e
  392. 020    *z
  393. 021    *y
  394. 022    *h
  395. 023    *i
  396. 024    *k
  397. 025    *l
  398. 026    *m
  399. 027    *n
  400. 030    *c
  401. 031    *p
  402. 032    *r
  403. 033    *s
  404. 034    *t
  405. 035    *u
  406. 036    *f
  407. 037    *x
  408. 040    *q
  409. 041    *w
  410. 042    Ve
  411. 043    Vh
  412. 044    Vp
  413. 045    Vr
  414. 046    ts
  415. 047    Vf
  416. 060    0
  417. 061    1
  418. 062    2
  419. 063    3
  420. 064    4
  421. 065    5
  422. 066    6
  423. 067    7
  424. 070    8
  425. 071    9
  426. 072    .
  427. 073    ,
  428. 074    <
  429. 075    /
  430. 076    >
  431. 077    *
  432. 100    pd
  433. 101    A
  434. 102    B
  435. 103    C
  436. 104    D
  437. 105    E
  438. 106    F
  439. 107    G
  440. 110    H
  441. 111    I
  442. 112    J
  443. 113    K
  444. 114    L
  445. 115    M
  446. 116    N
  447. 117    O
  448. 120    P
  449. 121    Q
  450. 122    R
  451. 123    S
  452. 124    T
  453. 125    U
  454. 126    V
  455. 127    W
  456. 130    X
  457. 131    Y
  458. 132    Z
  459. 140    li
  460. 141    a
  461. 142    b
  462. 143    c
  463. 144    d
  464. 145    e
  465. 146    f
  466. 147    g
  467. 150    h
  468. 151    i
  469. 152    j
  470. 153    k
  471. 154    l
  472. 155    m
  473. 156    n
  474. 157    o
  475. 160    p
  476. 161    q
  477. 162    r
  478. 163    s
  479. 164    t
  480. 165    u
  481. 166    v
  482. 167    w
  483. 170    x
  484. 171    y
  485. 172    z
  486. 173    ui
  487. 174    uj
  488. 177    cp
  489. 200    \&
  490. 200    \|
  491. 200    \^
  492. 201    ru
  493. 201    _
  494. 201    \_
  495. SHAR_EOF
  496. if test 766 -ne "`wc -c 'cmmi10'`"
  497. then
  498.     echo shar: error transmitting "'cmmi10'" '(should have been 766 characters)'
  499. fi
  500. echo shar: extracting "'cmr10'" '(874 characters)'
  501. if test -f 'cmr10'
  502. then
  503.     echo shar: over-writing existing file "'cmr10'"
  504. fi
  505. cat << \SHAR_EOF > 'cmr10'
  506. R
  507. 000    *G
  508. 001    *D
  509. 002    *H
  510. 003    *L
  511. 004    *C
  512. 005    *P
  513. 006    *S
  514. 007    *U
  515. 010    *F
  516. 011    *Q
  517. 012    *W
  518. 013    ff
  519. 014    fi
  520. 015    fl
  521. 016    Fi
  522. 017    Fl
  523. 020    ui
  524. 021    uj
  525. 022    \`
  526. 022    ga
  527. 023    \'
  528. 023    aa
  529. 024    hc
  530. 025    be
  531. 026    ma
  532. 027    ri
  533. 030    cd
  534. 031    ss
  535. 032    ae
  536. 033    oe
  537. 034    o/
  538. 035    AE
  539. 036    OE
  540. 037    O/
  541. 041    !
  542. 042    "
  543. 042    rq
  544. 043    #
  545. 044    $
  546. 045    %
  547. 046    &
  548. 047    '
  549. 050    (
  550. 051    )
  551. 052    *
  552. 053    +
  553. 054    ,
  554. 055    -
  555. 055    \-
  556. 055    hy
  557. 056    .
  558. 057    /
  559. 060    0
  560. 061    1
  561. 062    2
  562. 063    3
  563. 064    4
  564. 065    5
  565. 066    6
  566. 067    7
  567. 070    8
  568. 071    9
  569. 072    :
  570. 073    ;
  571. 074    !!
  572. 074    I!
  573. 075    =
  574. 076    I?
  575. 077    ?
  576. 100    @
  577. 101    A
  578. 102    B
  579. 103    C
  580. 104    D
  581. 105    E
  582. 106    F
  583. 107    G
  584. 110    H
  585. 111    I
  586. 112    J
  587. 113    K
  588. 114    L
  589. 115    M
  590. 116    N
  591. 117    O
  592. 120    P
  593. 121    Q
  594. 122    R
  595. 123    S
  596. 124    T
  597. 125    U
  598. 126    V
  599. 127    W
  600. 130    X
  601. 131    Y
  602. 132    Z
  603. 133    [
  604. 134    lq
  605. 135    ]
  606. 136    ^
  607. 137    dt
  608. 140    `
  609. 141    a
  610. 142    b
  611. 143    c
  612. 144    d
  613. 145    e
  614. 146    f
  615. 147    g
  616. 150    h
  617. 151    i
  618. 152    j
  619. 153    k
  620. 154    l
  621. 155    m
  622. 156    n
  623. 157    o
  624. 160    p
  625. 161    q
  626. 162    r
  627. 163    s
  628. 164    t
  629. 165    u
  630. 166    v
  631. 167    w
  632. 170    x
  633. 171    y
  634. 172    z
  635. 173    en
  636. 174    em
  637. 175    ''
  638. 176    ~
  639. 177    ..
  640. 177    um
  641. 200    \&
  642. 200    \|
  643. 200    \^
  644. SHAR_EOF
  645. if test 874 -ne "`wc -c 'cmr10'`"
  646. then
  647.     echo shar: error transmitting "'cmr10'" '(should have been 874 characters)'
  648. fi
  649. echo shar: extracting "'cmss10'" '(874 characters)'
  650. if test -f 'cmss10'
  651. then
  652.     echo shar: over-writing existing file "'cmss10'"
  653. fi
  654. cat << \SHAR_EOF > 'cmss10'
  655. H
  656. 000    *G
  657. 001    *D
  658. 002    *H
  659. 003    *L
  660. 004    *C
  661. 005    *P
  662. 006    *S
  663. 007    *U
  664. 010    *F
  665. 011    *Q
  666. 012    *W
  667. 013    ff
  668. 014    fi
  669. 015    fl
  670. 016    Fi
  671. 017    Fl
  672. 020    ui
  673. 021    uj
  674. 022    \`
  675. 022    ga
  676. 023    \'
  677. 023    aa
  678. 024    hc
  679. 025    be
  680. 026    ma
  681. 027    ri
  682. 030    cd
  683. 031    ss
  684. 032    ae
  685. 033    oe
  686. 034    o/
  687. 035    AE
  688. 036    OE
  689. 037    O/
  690. 041    !
  691. 042    "
  692. 042    rq
  693. 043    #
  694. 044    $
  695. 045    %
  696. 046    &
  697. 047    '
  698. 050    (
  699. 051    )
  700. 052    *
  701. 053    +
  702. 054    ,
  703. 055    -
  704. 055    \-
  705. 055    hy
  706. 056    .
  707. 057    /
  708. 060    0
  709. 061    1
  710. 062    2
  711. 063    3
  712. 064    4
  713. 065    5
  714. 066    6
  715. 067    7
  716. 070    8
  717. 071    9
  718. 072    :
  719. 073    ;
  720. 074    !!
  721. 074    I!
  722. 075    =
  723. 076    I?
  724. 077    ?
  725. 100    @
  726. 101    A
  727. 102    B
  728. 103    C
  729. 104    D
  730. 105    E
  731. 106    F
  732. 107    G
  733. 110    H
  734. 111    I
  735. 112    J
  736. 113    K
  737. 114    L
  738. 115    M
  739. 116    N
  740. 117    O
  741. 120    P
  742. 121    Q
  743. 122    R
  744. 123    S
  745. 124    T
  746. 125    U
  747. 126    V
  748. 127    W
  749. 130    X
  750. 131    Y
  751. 132    Z
  752. 133    [
  753. 134    lq
  754. 135    ]
  755. 136    ^
  756. 137    dt
  757. 140    `
  758. 141    a
  759. 142    b
  760. 143    c
  761. 144    d
  762. 145    e
  763. 146    f
  764. 147    g
  765. 150    h
  766. 151    i
  767. 152    j
  768. 153    k
  769. 154    l
  770. 155    m
  771. 156    n
  772. 157    o
  773. 160    p
  774. 161    q
  775. 162    r
  776. 163    s
  777. 164    t
  778. 165    u
  779. 166    v
  780. 167    w
  781. 170    x
  782. 171    y
  783. 172    z
  784. 173    en
  785. 174    em
  786. 175    ''
  787. 176    ~
  788. 177    ..
  789. 177    um
  790. 200    \&
  791. 200    \|
  792. 200    \^
  793. SHAR_EOF
  794. if test 874 -ne "`wc -c 'cmss10'`"
  795. then
  796.     echo shar: error transmitting "'cmss10'" '(should have been 874 characters)'
  797. fi
  798. echo shar: extracting "'cmssbx10'" '(875 characters)'
  799. if test -f 'cmssbx10'
  800. then
  801.     echo shar: over-writing existing file "'cmssbx10'"
  802. fi
  803. cat << \SHAR_EOF > 'cmssbx10'
  804. HB
  805. 000    *G
  806. 001    *D
  807. 002    *H
  808. 003    *L
  809. 004    *C
  810. 005    *P
  811. 006    *S
  812. 007    *U
  813. 010    *F
  814. 011    *Q
  815. 012    *W
  816. 013    ff
  817. 014    fi
  818. 015    fl
  819. 016    Fi
  820. 017    Fl
  821. 020    ui
  822. 021    uj
  823. 022    \`
  824. 022    ga
  825. 023    \'
  826. 023    aa
  827. 024    hc
  828. 025    be
  829. 026    ma
  830. 027    ri
  831. 030    cd
  832. 031    ss
  833. 032    ae
  834. 033    oe
  835. 034    o/
  836. 035    AE
  837. 036    OE
  838. 037    O/
  839. 041    !
  840. 042    "
  841. 042    rq
  842. 043    #
  843. 044    $
  844. 045    %
  845. 046    &
  846. 047    '
  847. 050    (
  848. 051    )
  849. 052    *
  850. 053    +
  851. 054    ,
  852. 055    -
  853. 055    \-
  854. 055    hy
  855. 056    .
  856. 057    /
  857. 060    0
  858. 061    1
  859. 062    2
  860. 063    3
  861. 064    4
  862. 065    5
  863. 066    6
  864. 067    7
  865. 070    8
  866. 071    9
  867. 072    :
  868. 073    ;
  869. 074    !!
  870. 074    I!
  871. 075    =
  872. 076    I?
  873. 077    ?
  874. 100    @
  875. 101    A
  876. 102    B
  877. 103    C
  878. 104    D
  879. 105    E
  880. 106    F
  881. 107    G
  882. 110    H
  883. 111    I
  884. 112    J
  885. 113    K
  886. 114    L
  887. 115    M
  888. 116    N
  889. 117    O
  890. 120    P
  891. 121    Q
  892. 122    R
  893. 123    S
  894. 124    T
  895. 125    U
  896. 126    V
  897. 127    W
  898. 130    X
  899. 131    Y
  900. 132    Z
  901. 133    [
  902. 134    lq
  903. 135    ]
  904. 136    ^
  905. 137    dt
  906. 140    `
  907. 141    a
  908. 142    b
  909. 143    c
  910. 144    d
  911. 145    e
  912. 146    f
  913. 147    g
  914. 150    h
  915. 151    i
  916. 152    j
  917. 153    k
  918. 154    l
  919. 155    m
  920. 156    n
  921. 157    o
  922. 160    p
  923. 161    q
  924. 162    r
  925. 163    s
  926. 164    t
  927. 165    u
  928. 166    v
  929. 167    w
  930. 170    x
  931. 171    y
  932. 172    z
  933. 173    en
  934. 174    em
  935. 175    ''
  936. 176    ~
  937. 177    ..
  938. 177    um
  939. 200    \&
  940. 200    \|
  941. 200    \^
  942. SHAR_EOF
  943. if test 875 -ne "`wc -c 'cmssbx10'`"
  944. then
  945.     echo shar: error transmitting "'cmssbx10'" '(should have been 875 characters)'
  946. fi
  947. echo shar: extracting "'cmssi10'" '(897 characters)'
  948. if test -f 'cmssi10'
  949. then
  950.     echo shar: over-writing existing file "'cmssi10'"
  951. fi
  952. cat << \SHAR_EOF > 'cmssi10'
  953. HI
  954. 000    *G
  955. 001    *D
  956. 002    *H
  957. 003    *L
  958. 004    *C
  959. 005    *P
  960. 006    *S
  961. 007    *U
  962. 010    *F
  963. 011    *Q
  964. 012    *W
  965. 013    ff
  966. 014    fi
  967. 015    fl
  968. 016    Fi
  969. 017    Fl
  970. 020    ui
  971. 021    uj
  972. 022    \`
  973. 022    ga
  974. 023    \'
  975. 023    aa
  976. 024    hc
  977. 025    be
  978. 026    ma
  979. 027    ri
  980. 030    cd
  981. 031    ss
  982. 032    ae
  983. 033    oe
  984. 034    o/
  985. 035    AE
  986. 036    OE
  987. 037    O/
  988. 041    !
  989. 042    "
  990. 042    rq
  991. 043    #
  992. 044    po
  993. 044    ps
  994. 045    %
  995. 046    &
  996. 047    '
  997. 050    (
  998. 051    )
  999. 052    *
  1000. 053    +
  1001. 053    pl
  1002. 054    ,
  1003. 055    -
  1004. 055    \-
  1005. 055    hy
  1006. 056    .
  1007. 057    /
  1008. 060    0
  1009. 061    1
  1010. 062    2
  1011. 063    3
  1012. 064    4
  1013. 065    5
  1014. 066    6
  1015. 067    7
  1016. 070    8
  1017. 071    9
  1018. 072    :
  1019. 073    ;
  1020. 074    !!
  1021. 074    I!
  1022. 075    =
  1023. 075    eq
  1024. 076    I?
  1025. 077    ?
  1026. 100    @
  1027. 101    A
  1028. 102    B
  1029. 103    C
  1030. 104    D
  1031. 105    E
  1032. 106    F
  1033. 107    G
  1034. 110    H
  1035. 111    I
  1036. 112    J
  1037. 113    K
  1038. 114    L
  1039. 115    M
  1040. 116    N
  1041. 117    O
  1042. 120    P
  1043. 121    Q
  1044. 122    R
  1045. 123    S
  1046. 124    T
  1047. 125    U
  1048. 126    V
  1049. 127    W
  1050. 130    X
  1051. 131    Y
  1052. 132    Z
  1053. 133    [
  1054. 134    lq
  1055. 135    ]
  1056. 136    ^
  1057. 137    dt
  1058. 140    `
  1059. 141    a
  1060. 142    b
  1061. 143    c
  1062. 144    d
  1063. 145    e
  1064. 146    f
  1065. 147    g
  1066. 150    h
  1067. 151    i
  1068. 152    j
  1069. 153    k
  1070. 154    l
  1071. 155    m
  1072. 156    n
  1073. 157    o
  1074. 160    p
  1075. 161    q
  1076. 162    r
  1077. 163    s
  1078. 164    t
  1079. 165    u
  1080. 166    v
  1081. 167    w
  1082. 170    x
  1083. 171    y
  1084. 172    z
  1085. 173    en
  1086. 174    em
  1087. 175    ''
  1088. 176    ~
  1089. 177    ..
  1090. 177    um
  1091. 200    \&
  1092. 200    \|
  1093. 200    \^
  1094. SHAR_EOF
  1095. if test 897 -ne "`wc -c 'cmssi10'`"
  1096. then
  1097.     echo shar: error transmitting "'cmssi10'" '(should have been 897 characters)'
  1098. fi
  1099. echo shar: extracting "'cmsy10'" '(809 characters)'
  1100. if test -f 'cmsy10'
  1101. then
  1102.     echo shar: over-writing existing file "'cmsy10'"
  1103. fi
  1104. cat << \SHAR_EOF > 'cmsy10'
  1105. S
  1106. 000    mi
  1107. 001    m.
  1108. 002    mu
  1109. 003    **
  1110. 004    di
  1111. 005    dm
  1112. 006    +-
  1113. 007    -+
  1114. 010    a+
  1115. 011    a-
  1116. 012    ax
  1117. 013    a/
  1118. 015    ci
  1119. 016    mc
  1120. 017    bu
  1121. 021    ==
  1122. 022    ib
  1123. 023    ip
  1124. 024    <=
  1125. 025    >=
  1126. 030    ap
  1127. 031    ~~
  1128. 032    sb
  1129. 033    sp
  1130. 034    <<
  1131. 035    >>
  1132. 036    l<
  1133. 037    r>
  1134. 040    <-
  1135. 041    ->
  1136. 042    ua
  1137. 043    da
  1138. 044    <>
  1139. 045    NE
  1140. 046    SE
  1141. 047    ~=
  1142. 050    <:
  1143. 051    :>
  1144. 051    im
  1145. 055    NW
  1146. 056    SW
  1147. 057    pt
  1148. 061    if
  1149. 062    mo
  1150. 063    cm
  1151. 064    tr
  1152. 066    sl
  1153. 070    fa
  1154. 071    te
  1155. 072    no
  1156. 073    es
  1157. 074    R#
  1158. 075    I#
  1159. 076    to
  1160. 077    bt
  1161. 100    al
  1162. 101    A
  1163. 102    B
  1164. 103    C
  1165. 104    D
  1166. 105    E
  1167. 106    F
  1168. 107    G
  1169. 110    H
  1170. 111    I
  1171. 112    J
  1172. 113    K
  1173. 114    L
  1174. 115    M
  1175. 116    N
  1176. 117    O
  1177. 120    P
  1178. 121    Q
  1179. 122    R
  1180. 123    S
  1181. 124    T
  1182. 125    U
  1183. 126    V
  1184. 127    W
  1185. 130    X
  1186. 131    Y
  1187. 132    X
  1188. 133    cu
  1189. 134    ca
  1190. 136    an
  1191. 137    \/
  1192. 137    lo
  1193. 140    |-
  1194. 140    st
  1195. 141    -|
  1196. 142    lf
  1197. 143    rf
  1198. 144    lc
  1199. 145    rc
  1200. 146    {
  1201. 147    }
  1202. 150    <
  1203. 151    >
  1204. 152    |
  1205. 152    or
  1206. 152    bv
  1207. 153    ||
  1208. 156    \
  1209. 160    sr
  1210. 162    gr
  1211. 163    is
  1212. 170    sc
  1213. 171    dg
  1214. 172    dd
  1215. 173    pp
  1216. 174    cS
  1217. 175    dS
  1218. 176    hS
  1219. 177    sS
  1220. 200    \&
  1221. 200    \|
  1222. 200    \^
  1223. 201    ru
  1224. 201    _
  1225. 201    \_
  1226. SHAR_EOF
  1227. if test 809 -ne "`wc -c 'cmsy10'`"
  1228. then
  1229.     echo shar: error transmitting "'cmsy10'" '(should have been 809 characters)'
  1230. fi
  1231. echo shar: extracting "'cmti10'" '(896 characters)'
  1232. if test -f 'cmti10'
  1233. then
  1234.     echo shar: over-writing existing file "'cmti10'"
  1235. fi
  1236. cat << \SHAR_EOF > 'cmti10'
  1237. I
  1238. 000    *G
  1239. 001    *D
  1240. 002    *H
  1241. 003    *L
  1242. 004    *C
  1243. 005    *P
  1244. 006    *S
  1245. 007    *U
  1246. 010    *F
  1247. 011    *Q
  1248. 012    *W
  1249. 013    ff
  1250. 014    fi
  1251. 015    fl
  1252. 016    Fi
  1253. 017    Fl
  1254. 020    ui
  1255. 021    uj
  1256. 022    \`
  1257. 022    ga
  1258. 023    \'
  1259. 023    aa
  1260. 024    hc
  1261. 025    be
  1262. 026    ma
  1263. 027    ri
  1264. 030    cd
  1265. 031    ss
  1266. 032    ae
  1267. 033    oe
  1268. 034    o/
  1269. 035    AE
  1270. 036    OE
  1271. 037    O/
  1272. 041    !
  1273. 042    "
  1274. 042    rq
  1275. 043    #
  1276. 044    po
  1277. 044    ps
  1278. 045    %
  1279. 046    &
  1280. 047    '
  1281. 050    (
  1282. 051    )
  1283. 052    *
  1284. 053    +
  1285. 053    pl
  1286. 054    ,
  1287. 055    -
  1288. 055    \-
  1289. 055    hy
  1290. 056    .
  1291. 057    /
  1292. 060    0
  1293. 061    1
  1294. 062    2
  1295. 063    3
  1296. 064    4
  1297. 065    5
  1298. 066    6
  1299. 067    7
  1300. 070    8
  1301. 071    9
  1302. 072    :
  1303. 073    ;
  1304. 074    !!
  1305. 074    I!
  1306. 075    =
  1307. 075    eq
  1308. 076    I?
  1309. 077    ?
  1310. 100    @
  1311. 101    A
  1312. 102    B
  1313. 103    C
  1314. 104    D
  1315. 105    E
  1316. 106    F
  1317. 107    G
  1318. 110    H
  1319. 111    I
  1320. 112    J
  1321. 113    K
  1322. 114    L
  1323. 115    M
  1324. 116    N
  1325. 117    O
  1326. 120    P
  1327. 121    Q
  1328. 122    R
  1329. 123    S
  1330. 124    T
  1331. 125    U
  1332. 126    V
  1333. 127    W
  1334. 130    X
  1335. 131    Y
  1336. 132    Z
  1337. 133    [
  1338. 134    lq
  1339. 135    ]
  1340. 136    ^
  1341. 137    dt
  1342. 140    `
  1343. 141    a
  1344. 142    b
  1345. 143    c
  1346. 144    d
  1347. 145    e
  1348. 146    f
  1349. 147    g
  1350. 150    h
  1351. 151    i
  1352. 152    j
  1353. 153    k
  1354. 154    l
  1355. 155    m
  1356. 156    n
  1357. 157    o
  1358. 160    p
  1359. 161    q
  1360. 162    r
  1361. 163    s
  1362. 164    t
  1363. 165    u
  1364. 166    v
  1365. 167    w
  1366. 170    x
  1367. 171    y
  1368. 172    z
  1369. 173    en
  1370. 174    em
  1371. 175    ''
  1372. 176    ~
  1373. 177    ..
  1374. 177    um
  1375. 200    \&
  1376. 200    \|
  1377. 200    \^
  1378. SHAR_EOF
  1379. if test 896 -ne "`wc -c 'cmti10'`"
  1380. then
  1381.     echo shar: error transmitting "'cmti10'" '(should have been 896 characters)'
  1382. fi
  1383. echo shar: extracting "'cmtt10'" '(860 characters)'
  1384. if test -f 'cmtt10'
  1385. then
  1386.     echo shar: over-writing existing file "'cmtt10'"
  1387. fi
  1388. cat << \SHAR_EOF > 'cmtt10'
  1389. C
  1390. 000    *G
  1391. 001    *D
  1392. 002    *H
  1393. 003    *L
  1394. 004    *C
  1395. 005    *P
  1396. 006    *S
  1397. 007    *U
  1398. 010    *F
  1399. 011    *Q
  1400. 012    *W
  1401. 013    ua
  1402. 014    da
  1403. 015    n'
  1404. 016    !!
  1405. 016    I!
  1406. 017    I?
  1407. 020    ui
  1408. 021    uj
  1409. 022    \`
  1410. 022    ga
  1411. 023    \'
  1412. 023    aa
  1413. 024    hc
  1414. 025    be
  1415. 026    ma
  1416. 027    ri
  1417. 030    cd
  1418. 031    ss
  1419. 032    ae
  1420. 033    oe
  1421. 034    o/
  1422. 035    AE
  1423. 036    OE
  1424. 037    O/
  1425. 040    __
  1426. 041    !
  1427. 042    "
  1428. 043    #
  1429. 044    $
  1430. 045    %
  1431. 046    &
  1432. 047    '
  1433. 050    (
  1434. 051    )
  1435. 052    *
  1436. 053    +
  1437. 054    ,
  1438. 055    -
  1439. 055    \-
  1440. 056    .
  1441. 057    /
  1442. 060    0
  1443. 061    1
  1444. 062    2
  1445. 063    3
  1446. 064    4
  1447. 065    5
  1448. 066    6
  1449. 067    7
  1450. 070    8
  1451. 071    9
  1452. 072    :
  1453. 073    ;
  1454. 074    <
  1455. 075    =
  1456. 076    >
  1457. 077    ?
  1458. 100    @
  1459. 101    A
  1460. 102    B
  1461. 103    C
  1462. 104    D
  1463. 105    E
  1464. 106    F
  1465. 107    G
  1466. 110    H
  1467. 111    I
  1468. 112    J
  1469. 113    K
  1470. 114    L
  1471. 115    M
  1472. 116    N
  1473. 117    O
  1474. 120    P
  1475. 121    Q
  1476. 122    R
  1477. 123    S
  1478. 124    T
  1479. 125    U
  1480. 126    V
  1481. 127    W
  1482. 130    X
  1483. 131    Y
  1484. 132    Z
  1485. 133    [
  1486. 134    \
  1487. 135    ]
  1488. 136    ^
  1489. 137    _
  1490. 140    `
  1491. 141    a
  1492. 142    b
  1493. 143    c
  1494. 144    d
  1495. 145    e
  1496. 146    f
  1497. 147    g
  1498. 150    h
  1499. 151    i
  1500. 152    j
  1501. 153    k
  1502. 154    l
  1503. 155    m
  1504. 156    n
  1505. 157    o
  1506. 160    p
  1507. 161    q
  1508. 162    r
  1509. 163    s
  1510. 164    t
  1511. 165    u
  1512. 166    v
  1513. 167    w
  1514. 170    x
  1515. 171    y
  1516. 172    z
  1517. 173    {
  1518. 174    |
  1519. 175    }
  1520. 176    ~
  1521. 177    ..
  1522. 177    um
  1523. 200    \&
  1524. 200    \|
  1525. 200    \^
  1526. SHAR_EOF
  1527. if test 860 -ne "`wc -c 'cmtt10'`"
  1528. then
  1529.     echo shar: error transmitting "'cmtt10'" '(should have been 860 characters)'
  1530. fi
  1531. echo shar: extracting "'ditdvi.1'" '(636 characters)'
  1532. if test -f 'ditdvi.1'
  1533. then
  1534.     echo shar: over-writing existing file "'ditdvi.1'"
  1535. fi
  1536. cat << \SHAR_EOF > 'ditdvi.1'
  1537. .TH DITDVI 1 4/9/88
  1538. .CM 1
  1539. .SH "NAME"
  1540. ditdvi \- convert ditroff output to DVI
  1541. .SH "SYNOPSIS"
  1542. ditdvi [\fB\-o\fP] < file.di > file.dvi
  1543. .SH "DESCRIPTION"
  1544. \fIDitdvi\fP converts ditroff(1) output to DVI output.
  1545. The ditroff output should have been generated for a
  1546. virtual DVI printer.
  1547. .PP
  1548. The \fB\-o\fP flag turns on the standard 1 inch top and
  1549. left margins for the output. This option is for previewing
  1550. the DVI output with DVI previewers that crop margins.
  1551. .SH "FILES"
  1552. FONTDIR where the DESC file for the virtual printer lives
  1553. .SH "SEE ALSO"
  1554. ditroff(1), makedev(1), tfm2desc(1)
  1555. .SH "DIAGNOSTICS"
  1556. Hopefully self-explanatory. 
  1557. .SH "BUGS"
  1558. Lots.
  1559. SHAR_EOF
  1560. if test 636 -ne "`wc -c 'ditdvi.1'`"
  1561. then
  1562.     echo shar: error transmitting "'ditdvi.1'" '(should have been 636 characters)'
  1563. fi
  1564. echo shar: extracting "'ditdvi.c'" '(646 characters)'
  1565. if test -f 'ditdvi.c'
  1566. then
  1567.     echo shar: over-writing existing file "'ditdvi.c'"
  1568. fi
  1569. cat << \SHAR_EOF > 'ditdvi.c'
  1570. #include    <stdio.h>
  1571. #include    "ditdvi.h"
  1572.  
  1573. char        pageoffset    = 1;
  1574. char        *prog_name;
  1575.  
  1576. /*VARARGS1*/
  1577. fatal(s, arg1, arg2)
  1578.     char        *s;
  1579.     int        arg1, arg2;
  1580. {
  1581.     (void)fprintf(stderr, s, arg1, arg2);
  1582.     exit(1);
  1583. }
  1584.  
  1585. main(argc, argv)
  1586.     int        argc;
  1587.     char        *argv[];
  1588. {
  1589.     register int    c;
  1590.     char        *rindex();
  1591.     int        getopt();
  1592.     extern int    optind;
  1593.     extern char    *optarg;
  1594.  
  1595.     if ((prog_name = rindex(argv[0], '/')) == NULL)
  1596.         prog_name = argv[0];
  1597.     else
  1598.         ++prog_name;
  1599.     while ((c = getopt(argc, argv, "o")) != EOF)
  1600.     {
  1601.         switch (c)
  1602.         {
  1603.         case 'o':
  1604.             pageoffset = 0;
  1605.             break;
  1606.         default:
  1607.             fatal("Usage: %s [-o] < f.di > f.dvi\n", prog_name);
  1608.             break;
  1609.         }
  1610.     }
  1611.     reader();
  1612.     exit(0);
  1613. }
  1614. SHAR_EOF
  1615. if test 646 -ne "`wc -c 'ditdvi.c'`"
  1616. then
  1617.     echo shar: error transmitting "'ditdvi.c'" '(should have been 646 characters)'
  1618. fi
  1619. echo shar: extracting "'ditdvi.h'" '(2724 characters)'
  1620. if test -f 'ditdvi.h'
  1621. then
  1622.     echo shar: over-writing existing file "'ditdvi.h'"
  1623. fi
  1624. cat << \SHAR_EOF > 'ditdvi.h'
  1625. #ifndef        FONTDIR
  1626. #define        FONTDIR        "/usr/lib/ditroff"
  1627. #endif
  1628.  
  1629. #define        DEF_DEV        "dvi"
  1630. #define        NFONTS        100
  1631. #define        NSIZES        20
  1632.  
  1633. #define        RULE_CHAR    0201        /* put here by tfm2desc */
  1634.  
  1635. char        *strcpy(), *sprintf();
  1636.  
  1637. typedef        unsigned char    uchar;
  1638.  
  1639. extern char    pageoffset;
  1640. extern char    *prog_name;
  1641.  
  1642. /*
  1643. **    characteristics of a typesetter
  1644. */
  1645.  
  1646. typedef struct tdev {
  1647.       unsigned  short filesize;    /* number of bytes in file, */
  1648.                 /* excluding dev part */
  1649.     short    res;        /* basic resolution in goobies/inch */
  1650.     short    hor;        /* goobies horizontally */
  1651.     short    vert;
  1652.     short    unitwidth;    /* size at which widths are given, in effect */
  1653.     short    nfonts;        /* number of fonts physically available */
  1654.     short    nsizes;        /* number of sizes it has */
  1655.     short    sizescale;    /* scaling for fractional point sizes */
  1656.     short    paperwidth;    /* max line length in units */
  1657.     short    paperlength;    /* max paper length in units */
  1658.     short    nchtab;        /* number of funny names in chtab */
  1659.     short    lchname;    /* length of chname table */
  1660.     short    spare1;        /* in case of expansion */
  1661.     short    spare2;
  1662.     } tdev;
  1663.  
  1664. typedef struct tfont {        /* characteristics of a font */
  1665.     uchar    nwfont;        /* number of width entries for this font */
  1666.     char    specfont;    /* 1 == special font */
  1667.     char    ligfont;    /* 1 == ligatures exist on this font */
  1668.     char    spare1;        /* unused for now */
  1669.     char    namefont[10];    /* name of this font (e.g., "R" */
  1670.     char    intname[10];    /* internal name on device, in ascii */
  1671.     } tfont;
  1672.  
  1673. /* ligatures, ORed into ligfont */
  1674.  
  1675. #define    LFF    01
  1676. #define    LFI    02
  1677. #define    LFL    04
  1678. #define    LFFI    010
  1679. #define    LFFL    020
  1680.  
  1681. typedef struct lookup {
  1682.     char        *chname;
  1683.     short        ordinal;
  1684.     } lookup;
  1685.  
  1686. typedef struct settings {
  1687.     char        s_ts_name[20];        /* name of typesetter */
  1688.     char        *s_font_name;        /* current font name */
  1689.     int        s_font_num;        /* current font number */
  1690.     int        s_point_size;        /* current point size */
  1691.     int        s_point_index;        /* index into pstab and raster */
  1692.     int        s_page_num;        /* current page number */
  1693.     int        s_H, s_V;        /* H and V ints */
  1694.     int        s_resolution, s_horizontal,
  1695.             s_vertical;        /* of typesetter */
  1696.     } settings;
  1697.  
  1698. typedef    struct fontdes {
  1699.     tfont        *tfontp;        /* font entry */
  1700.     uchar        *widtab;        /* width table */
  1701.     uchar        *kerntab;        /* kerning table */
  1702.     uchar        *codetab;        /* code table */
  1703.     uchar        *fitab;            /* font index table */
  1704.     int        texfont[NSIZES];    /* number of font in DVI file */
  1705.     } fontdes;
  1706.  
  1707. /* define some macros for convenient reference to fields */
  1708. #define    n_width        tfontp->nwfont        /* first thing in font entry */
  1709. #define    font_name    tfontp->namefont    /* array of char */
  1710. #define    int_name    tfontp->intname        /* array of char */
  1711.  
  1712. extern tdev    dev;
  1713. extern int    halfwidth;
  1714. extern short    *pstab;
  1715. extern lookup    *specialtab;
  1716. extern settings    engine;                /* where we are at now */
  1717. extern fontdes    fonts[NFONTS];
  1718. SHAR_EOF
  1719. if test 2724 -ne "`wc -c 'ditdvi.h'`"
  1720. then
  1721.     echo shar: error transmitting "'ditdvi.h'" '(should have been 2724 characters)'
  1722. fi
  1723. echo shar: extracting "'dvi.c'" '(3825 characters)'
  1724. if test -f 'dvi.c'
  1725. then
  1726.     echo shar: over-writing existing file "'dvi.c'"
  1727. fi
  1728. cat << \SHAR_EOF > 'dvi.c'
  1729. #include    <stdio.h>
  1730. #include    "dvi.h"
  1731.  
  1732. /*
  1733. **    Code generation routines for DVI
  1734. **    See dvitype.web in TeX sources for description of DVI format.
  1735. */
  1736.  
  1737. int        filepos = 0;
  1738. static int    postpos;
  1739.  
  1740. static put1(c)
  1741.     int        c;
  1742. {
  1743.     putchar(c);
  1744.     ++filepos;
  1745. }
  1746.  
  1747. static put2(c)
  1748.     int        c;
  1749. {
  1750.     put1((c >> 8) & 0xff);
  1751.     put1(c & 0xff);
  1752. }
  1753.  
  1754. static put3(c)
  1755.     int        c;
  1756. {
  1757.     put1((c >> 16) & 0xff);
  1758.     put1((c >> 8) & 0xff);
  1759.     put1(c & 0xff);
  1760. }
  1761.  
  1762. static put4(c)
  1763.     int        c;
  1764. {
  1765.     put1((c >> 24) & 0xff);
  1766.     put1((c >> 16) & 0xff);
  1767.     put1((c >> 8) & 0xff);
  1768.     put1(c & 0xff);
  1769. }
  1770.  
  1771. set_char(c)
  1772.     int        c;
  1773. {
  1774.     if (0 <= c && c < 128)
  1775.         put1(SET_CHAR + c);
  1776.     else if (128 <= c && c < 256)
  1777.     {
  1778.         put1(SET1);
  1779.         put1(c);
  1780.     }
  1781.     else if (256 <= c && c < 65536)
  1782.     {
  1783.         put1(SET2);
  1784.         put2(c);
  1785.     }
  1786.     else if (65536 <= c && c < (1 << 24))
  1787.     {
  1788.         put1(SET3);
  1789.         put3(c);
  1790.     }
  1791.     else
  1792.     {
  1793.         put1(SET4);
  1794.         put4(c);
  1795.     }
  1796. }
  1797.  
  1798. set_rule(a, b)
  1799.     int        a, b;
  1800. {
  1801.     put1(SET_RULE);
  1802.     put4(a);
  1803.     put4(b);
  1804. }
  1805.  
  1806. put_char(c)
  1807.     int        c;
  1808. {
  1809.     if (0 <= c && c < 256)
  1810.     {
  1811.         put1(PUT1);
  1812.         put1(c);
  1813.     }
  1814.     else if (256 <= c && c < 65536)
  1815.     {
  1816.         put1(PUT2);
  1817.         put2(c);
  1818.     }
  1819.     else if (65536 <= c && c < (1 << 24))
  1820.     {
  1821.         put1(PUT3);
  1822.         put3(c);
  1823.     }
  1824.     else
  1825.     {
  1826.         put1(PUT4);
  1827.         put4(c);
  1828.     }
  1829. }
  1830.  
  1831. put_rule(a, b)
  1832.     int        a, b;
  1833. {
  1834.     put1(PUT_RULE);
  1835.     put4(a);
  1836.     put4(b);
  1837. }
  1838.  
  1839. int bop(counts, backptr)
  1840.     int        counts[];
  1841.     int        backptr;
  1842. {
  1843.     register int    i, prev;
  1844.  
  1845.     prev = filepos;
  1846.     put1(BOP);
  1847.     for (i = 0; i < 10; ++i)
  1848.         put4(counts[i]);
  1849.     put4(backptr);
  1850.     return (prev);            /* return position of this bop */
  1851. }
  1852.  
  1853. eop()
  1854. {
  1855.     put1(EOP);
  1856. }
  1857.  
  1858. push()
  1859. {
  1860.     put1(PUSH);
  1861. }
  1862.  
  1863. pop()
  1864. {
  1865.     put1(POP);
  1866. }
  1867.  
  1868. right(x)
  1869.     int        x;
  1870. {
  1871.     if (-128 <= x && x < 128)
  1872.     {
  1873.         put1(RIGHT1);
  1874.         put1(x & 0xff);
  1875.     }
  1876.     else if (-32768 <= x && x < 32768)
  1877.     {
  1878.         put1(RIGHT2);
  1879.         put2(x & 0xffff);
  1880.     }
  1881.     else if (-(1 << 23) <= x && x < (1 >> 23))
  1882.     {
  1883.         put1(RIGHT3);
  1884.         put3(x & 0xffffff);
  1885.     }
  1886.     else
  1887.     {
  1888.         put1(RIGHT4);
  1889.         put4(x);
  1890.     }
  1891. }
  1892.  
  1893. down(y)
  1894.     int        y;
  1895. {
  1896.     if (-128 <= y && y < 128)
  1897.     {
  1898.         put1(DOWN1);
  1899.         put1(y & 0xff);
  1900.     }
  1901.     else if (-32768 <= y && y < 32768)
  1902.     {
  1903.         put1(DOWN2);
  1904.         put2(y & 0xffff);
  1905.     }
  1906.     else if (-(1 << 23) <= y && y < (1 >> 23))
  1907.     {
  1908.         put1(DOWN3);
  1909.         put3(y & 0xffffff);
  1910.     }
  1911.     else
  1912.     {
  1913.         put1(DOWN4);
  1914.         put4(y);
  1915.     }
  1916. }
  1917.  
  1918. fnt_num(n)
  1919.     int        n;
  1920. {
  1921.     if (0 <= n && n < 64)
  1922.         put1(FNT_NUM + n);
  1923.     else if (64 <= n && n <= 256)
  1924.     {
  1925.         put1(FNT1);
  1926.         put1(n);
  1927.     }
  1928.     else if (256 <= n && n <= 65536)
  1929.     {
  1930.         put1(FNT2);
  1931.         put2(n);
  1932.     }
  1933.     else if (65536 <= n && n <= (1 >> 24))
  1934.     {
  1935.         put1(FNT3);
  1936.         put3(n);
  1937.     }
  1938.     else
  1939.     {
  1940.         put1(FNT4);
  1941.         put4(n);
  1942.     }
  1943. }
  1944.  
  1945. xxx(s)
  1946.     char        *s;
  1947. {
  1948.     register int    len = strlen(s);
  1949.  
  1950.     if (0 <= len && len < 256)
  1951.     {
  1952.         put1(XXX1);
  1953.         put1(len);
  1954.     }
  1955. /*
  1956.     use only XXX1 and XXX4
  1957.     else if (256 <= len && len < 65536)
  1958.     {
  1959.         put1(XXX2);
  1960.         put2(len);
  1961.     }
  1962.     else if (65536 <= len && len < (1 << 24))
  1963.     {
  1964.         put1(XXX3);
  1965.         put3(len);
  1966. */
  1967.     else
  1968.     {
  1969.         put1(XXX4);
  1970.         put4(len);
  1971.     }
  1972.     while (*s != '\0')
  1973.         put1(*s++);
  1974. }
  1975.  
  1976. fnt_def(k, c, s, d, a, l)
  1977.     int        k, c, s, d;
  1978.     char        *a, *l;
  1979. {
  1980.     register int    la = strlen(a), ll = strlen(l);
  1981.  
  1982.     if (0 <= k && k < 256)
  1983.     {
  1984.         put1(FNT_DEF1);
  1985.         put1(k);
  1986.     }
  1987.     else if (256 <= k && k < 65536)
  1988.     {
  1989.         put1(FNT_DEF2);
  1990.         put2(k);
  1991.     }
  1992.     else if (65536 <= k && k < (1 >> 24))
  1993.     {
  1994.         put1(FNT_DEF3);
  1995.         put3(k);
  1996.     }
  1997.     else
  1998.     {
  1999.         put1(FNT_DEF4);
  2000.         put4(k);
  2001.     }
  2002.     put4(c);
  2003.     put4(s);
  2004.     put4(d);
  2005.     put1(la);
  2006.     put1(ll);
  2007.     while (*a != '\0')
  2008.         put1(*a++);
  2009.     while (*l != '\0')
  2010.         put1(*l++);
  2011. }
  2012.  
  2013. pre(num, den, mag, k)
  2014.     int        num, den, mag;
  2015.     char        *k;
  2016. {
  2017.     register int    len = strlen(k);
  2018.  
  2019.     put1(PRE);
  2020.     put1(DVI_VERSION);
  2021.     put4(num);
  2022.     put4(den);
  2023.     put4(mag);
  2024.     put1(len);
  2025.     while (*k != '\0')
  2026.         put1(*k++);
  2027. }
  2028.  
  2029. post(back, num, den, mag, height, width, stack, pages)
  2030. {
  2031.     postpos = filepos;
  2032.     put1(POST);
  2033.     put4(back);
  2034.     put4(num);
  2035.     put4(den);
  2036.     put4(mag);
  2037.     put4(height);
  2038.     put4(width);
  2039.     put2(stack);
  2040.     put2(pages);
  2041. }
  2042.  
  2043. post_post()
  2044. {
  2045.     register int    i;
  2046.  
  2047.     put1(POST_POST);
  2048.     put4(postpos);
  2049.     put1(DVI_VERSION);
  2050.     for (i = 0; i < 4; ++i)
  2051.         put1(SIGNATURE);
  2052.     while ((filepos & 0x3) != 0)
  2053.         put1(SIGNATURE);
  2054. }
  2055. SHAR_EOF
  2056. if test 3825 -ne "`wc -c 'dvi.c'`"
  2057. then
  2058.     echo shar: error transmitting "'dvi.c'" '(should have been 3825 characters)'
  2059. fi
  2060. echo shar: extracting "'dvi.h'" '(1103 characters)'
  2061. if test -f 'dvi.h'
  2062. then
  2063.     echo shar: over-writing existing file "'dvi.h'"
  2064. fi
  2065. cat << \SHAR_EOF > 'dvi.h'
  2066. #define    DVI_VERSION    2
  2067.  
  2068. #define    SET_CHAR    0
  2069. #define    SET1        128
  2070. #define    SET2        129
  2071. #define    SET3        130
  2072. #define    SET4        131
  2073. #define    SET_RULE    132
  2074. #define    PUT1        133
  2075. #define    PUT2        134
  2076. #define    PUT3        135
  2077. #define    PUT4        136
  2078. #define    PUT_RULE    137
  2079. #define    NOP        138
  2080. #define    BOP        139
  2081. #define    EOP        140
  2082. #define    PUSH        141
  2083. #define    POP        142
  2084. #define    RIGHT1        143
  2085. #define    RIGHT2        144
  2086. #define    RIGHT3        145
  2087. #define    RIGHT4        146
  2088. #define    W0        147
  2089. #define    W1        148
  2090. #define    W2        149
  2091. #define    W3        150
  2092. #define    W4        151
  2093. #define    X0        152
  2094. #define    X1        153
  2095. #define    X2        154
  2096. #define    X3        155
  2097. #define    X4        156
  2098. #define    DOWN1        157
  2099. #define    DOWN2        158
  2100. #define    DOWN3        159
  2101. #define    DOWN4        160
  2102. #define    Y0        161
  2103. #define    Y1        162
  2104. #define    Y2        163
  2105. #define    Y3        164
  2106. #define    Z0        166
  2107. #define    Z1        167
  2108. #define    Z2        168
  2109. #define    Z3        169
  2110. #define    Z4        170
  2111. #define    FNT_NUM        171
  2112. #define    FNT1        235
  2113. #define    FNT2        236
  2114. #define    FNT3        237
  2115. #define    FNT4        238
  2116. #define    XXX1        239
  2117. #define    XXX2        240
  2118. #define    XXX3        241
  2119. #define    XXX4        242
  2120. #define    FNT_DEF1    243
  2121. #define    FNT_DEF2    244
  2122. #define    FNT_DEF3    245
  2123. #define    FNT_DEF4    246
  2124. #define    PRE        247
  2125. #define    POST        248
  2126. #define    POST_POST    249
  2127.  
  2128. #define    SIGNATURE    223
  2129. SHAR_EOF
  2130. if test 1103 -ne "`wc -c 'dvi.h'`"
  2131. then
  2132.     echo shar: error transmitting "'dvi.h'" '(should have been 1103 characters)'
  2133. fi
  2134. echo shar: extracting "'fontfile.c'" '(4416 characters)'
  2135. if test -f 'fontfile.c'
  2136. then
  2137.     echo shar: over-writing existing file "'fontfile.c'"
  2138. fi
  2139. cat << \SHAR_EOF > 'fontfile.c'
  2140. #include    <stdio.h>
  2141. #include    "ditdvi.h"
  2142.  
  2143. /*
  2144. **    Routines to read ditroff DESC file.
  2145. */
  2146.  
  2147. tdev    dev;
  2148. int    halfwidth;
  2149. short    *pstab;
  2150. lookup    *specialtab;
  2151. fontdes    fonts[NFONTS];
  2152.  
  2153. static char *smalloc(n)
  2154.     int        n;
  2155. /*
  2156. **    Get memory, or die
  2157. */
  2158. {
  2159.     register char    *p;
  2160.     char        *malloc();
  2161.  
  2162.     if ((p = malloc(n)) == NULL)
  2163.         fatal("No more memory\n");
  2164.     return (p);
  2165. }
  2166.  
  2167. int readfontdir()
  2168. /*
  2169. **    Read in the information from the DESC file, storing it in
  2170. **    the font info array.
  2171. */
  2172. {
  2173.     register int    i;
  2174.     register char    *filedata, *chname;
  2175.     register short    *chtab;
  2176.     register FILE    *f;
  2177.     char        fname[100];
  2178.     char        *sprintf();
  2179.  
  2180.     (void)sprintf(fname, "%s/dev%s/DESC.out", FONTDIR, engine.s_ts_name);
  2181.     if ((f = fopen(fname, "r")) == NULL)
  2182.     {
  2183.         perror(fname);
  2184.         return (0);
  2185.     }
  2186.     if (fread((char *)&dev, sizeof(char), sizeof(tdev), f) != sizeof(tdev))
  2187.         return (0);
  2188.     halfwidth = dev.unitwidth / 2;
  2189.     if (dev.nfonts >= NFONTS)
  2190.         fatal("Font capacity of %d fonts exceeded, reconfigure\n", NFONTS - 1);
  2191.     if (dev.nsizes >= NSIZES)
  2192.         fatal("Pointsize capacity of %d sizes exceeded, reconfigure\n", NSIZES);
  2193.  
  2194.     for (i = 0; i < NFONTS; ++i)        /* zero descriptors */
  2195.     {
  2196.         register fontdes    *f;
  2197.         register int        j;
  2198.  
  2199.         f = &fonts[i];
  2200.         f->tfontp = (tfont *)0;
  2201.         f->codetab = f->fitab = (uchar *)0;
  2202.         for (j = 0; j < NSIZES; ++j)
  2203.             f->texfont[j] = -1;    /* initially unloaded */
  2204.     }
  2205.  
  2206.     filedata = smalloc(dev.filesize);
  2207.     if (fread(filedata, sizeof(char), dev.filesize, f) != dev.filesize)
  2208.         fatal("Short read on %s\n", fname);
  2209.     (void)fclose(f);
  2210.     pstab = (short *)filedata;
  2211.     filedata += (dev.nsizes + 1) * sizeof(short);
  2212.     chtab = (short *)filedata;
  2213.     filedata += dev.nchtab * sizeof(short);
  2214.     chname = filedata;
  2215.     filedata += dev.lchname;
  2216.     makespecialtab(dev.nchtab, chname, chtab);
  2217. #ifdef    DEBUG_FONTS
  2218.     dumptables();
  2219. #endif    DEBUG_FONTS
  2220.     for (i = 1; i <= dev.nfonts; i++)
  2221.     {
  2222.         register int        nw;
  2223.  
  2224.         fonts[i].tfontp = (tfont *)filedata;
  2225.         nw = fonts[i].n_width;
  2226.         filedata += sizeof(tfont);
  2227.         fonts[i].widtab = (uchar *)filedata;
  2228.         filedata += nw;
  2229.         fonts[i].kerntab = (uchar *)filedata;
  2230.         filedata += nw;
  2231.         fonts[i].codetab = (uchar *)filedata;
  2232.         filedata += nw;
  2233.         fonts[i].fitab = (uchar *)filedata;
  2234.         filedata += dev.nchtab + (128 - 32);
  2235.     }
  2236. #ifdef    DEBUG_FONTS
  2237.     dumpfonts();
  2238. #endif    DEBUG_FONTS
  2239.     return (1);
  2240. }
  2241.  
  2242. static int speccmp(l1, l2)
  2243.     lookup        *l1, *l2;
  2244. {
  2245.     return (strcmp(l1->chname, l2->chname));
  2246. }
  2247.  
  2248. makespecialtab(nspecials, strings, offsets)
  2249.     int        nspecials;
  2250.     char        *strings;
  2251.     short        offsets[];
  2252. {
  2253.     register int    i;
  2254.  
  2255.     specialtab = (lookup *)smalloc(nspecials * sizeof(lookup));
  2256.     for (i = 0; i < nspecials; ++i)
  2257.     {
  2258.         specialtab[i].ordinal = i;
  2259.         specialtab[i].chname = strings + offsets[i];
  2260.     }
  2261.     qsort((char *)specialtab, nspecials, sizeof(lookup), speccmp);
  2262. #ifdef    DEBUG_FONTS
  2263.     for (i = 0; i < nspecials; ++i)
  2264.         printf("%s %d\n", specialtab[i].chname, specialtab[i].ordinal);
  2265. #endif    DEBUG_FONTS
  2266. }
  2267.  
  2268. #ifdef    DEBUG_FONTS
  2269. static dumptables()
  2270. /*
  2271. **    Print font size tables
  2272. */
  2273. {
  2274.     register int        i;
  2275.  
  2276.     printf("Point size table\n");
  2277.     for (i = 0; i <= dev.nsizes; ++i)
  2278.     {
  2279.         printf("%3d", pstab[i]);
  2280.         if (i % 20 == 19)
  2281.             putchar('\n');
  2282.         else
  2283.             putchar(' ');
  2284.     }
  2285.     putchar('\n');
  2286.     printf("Special chars\n");
  2287.     for (i = 0; i < dev.nchtab; ++i)
  2288.     {
  2289.         printf("%s", &chname[chtab[i]]);
  2290.         if (i % 20 == 19)
  2291.             putchar('\n');
  2292.         else
  2293.             putchar(' ');
  2294.     }
  2295.     putchar('\n');
  2296. }
  2297.  
  2298. static dumpfonts()
  2299. /*
  2300. **    Print out a human readable representation of fonts for
  2301. **    debugging purposes.
  2302. */
  2303. {
  2304.     register int        i;
  2305.  
  2306.     for (i = 1; i < NFONTS; ++i)
  2307.     {
  2308.         if (fonts[i].tfontp != NULL)
  2309.             dumponefont(i);
  2310.     }
  2311. }
  2312.  
  2313. static dumponefont(n)
  2314.     int            n;
  2315. /*
  2316. **    Say all we know about this font
  2317. */
  2318. {
  2319.     register tfont        *tf;
  2320.     register uchar        *t;
  2321.     register int        i, nw;
  2322.  
  2323.     tf = fonts[n].tfontp;
  2324.     printf("%s (%s), %d entries,%s%s\n",
  2325.         tf->namefont, tf->intname, (int)tf->nwfont,
  2326.         tf->specfont ? " special" : " ",
  2327.         tf->ligfont ? " ligatures" : " ");
  2328.     nw = tf->nwfont;
  2329.     t = fonts[n].widtab;
  2330.     printf("Width table\n");
  2331.     for (i = 0; i < nw; ++i)
  2332.     {
  2333.         printf("%3d", t[i]);
  2334.         if (i % 20 == 19)
  2335.             putchar('\n');
  2336.         else
  2337.             putchar(' ');
  2338.     }
  2339.     putchar('\n');
  2340.     t = fonts[n].codetab;
  2341.     printf("Code table\n");
  2342.     for (i = 0; i < nw; ++i)
  2343.     {
  2344.         printf("%3d", t[i]);
  2345.         if (i % 20 == 19)
  2346.             putchar('\n');
  2347.         else
  2348.             putchar(' ');
  2349.     }
  2350.     putchar('\n');
  2351.     t = fonts[n].fitab;
  2352.     printf("Font index table\n");
  2353.     for (i = 0; i < dev.nchtab; ++i)
  2354.     {
  2355.         printf("%3d", t[i]);
  2356.         if (i % 20 == 19)
  2357.             putchar('\n');
  2358.         else
  2359.             putchar(' ');
  2360.     }
  2361.     putchar('\n');
  2362. }
  2363. #endif    DEBUG_FONTS
  2364. SHAR_EOF
  2365. if test 4416 -ne "`wc -c 'fontfile.c'`"
  2366. then
  2367.     echo shar: error transmitting "'fontfile.c'" '(should have been 4416 characters)'
  2368. fi
  2369. echo shar: extracting "'getspecials'" '(191 characters)'
  2370. if test -f 'getspecials'
  2371. then
  2372.     echo shar: over-writing existing file "'getspecials'"
  2373. fi
  2374. cat << \SHAR_EOF > 'getspecials'
  2375. #! /bin/sh
  2376. #
  2377. #    This shell script extracts all the two character sequences for
  2378. #    inclusion in the DESC file
  2379. #
  2380. cat cm*10 \
  2381.     | sed -e '/    .$/d' -e '/^.$/d' -e '/^..$/d' -e 's/.*    //' \
  2382.     | sort -u
  2383. SHAR_EOF
  2384. if test 191 -ne "`wc -c 'getspecials'`"
  2385. then
  2386.     echo shar: error transmitting "'getspecials'" '(should have been 191 characters)'
  2387. fi
  2388. chmod +x 'getspecials'
  2389. echo shar: extracting "'reader.c'" '(10736 characters)'
  2390. if test -f 'reader.c'
  2391. then
  2392.     echo shar: over-writing existing file "'reader.c'"
  2393. fi
  2394. cat << \SHAR_EOF > 'reader.c'
  2395. #include    <stdio.h>
  2396. #include    <ctype.h>
  2397. #include    "ditdvi.h"
  2398.  
  2399. /*
  2400. **    The heart of the converter, read ditroff, spit out DVI.
  2401. */
  2402.  
  2403. #undef        DEBUG_INPUT
  2404. #undef        USE_PUT
  2405.  
  2406. /* same values as TeX82 uses */
  2407. #define        FIX        (1<<16)
  2408. #define        CPIN        7227        /* centipoints in an inch */
  2409. #define        NUM        25400000
  2410. #define        DEN        (CPIN*FIX)
  2411. #define        UNITY        1000
  2412.  
  2413. /* paper dimensions */
  2414. #define        HEIGHT        (11*72*FIX)    /* height in scaled pts */
  2415. #define        WIDTH        (17*36*FIX)    /* width in scaled pts */
  2416.  
  2417. /* goobies to scaled points */
  2418. #define        gtosp(g)    ((g)*scale)
  2419.  
  2420. #define        vmove(n)    down(gtosp(n)), engine.s_V += (n)
  2421.  
  2422. settings    engine    = {
  2423.     DEF_DEV, "R",            /* s_ts_name, s_font_name */
  2424.     0, 0,                /* s_font_num, s_point_size */
  2425.     0,                /* s_point_index */
  2426.     0,                /* s_page_num */
  2427.     0, 0,                /* s_H, s_V */
  2428.     0, 0, 0,            /* resolution, horizontal, vertical */
  2429. };
  2430.  
  2431. int    counters[10]    = { 0 };
  2432. int    scale        = 0;
  2433. int    last_move    = 0;
  2434. char    fontchanged    = 0;
  2435.  
  2436. int    mag        = UNITY;
  2437. int    back        = -1;        /* back pointer for bop */
  2438. char    bopsent        = 0;
  2439.  
  2440. int    fontind        = 0;
  2441.  
  2442. struct fonttab {
  2443.     int        font;
  2444.     int        size;
  2445.     } fonttab[NFONTS];
  2446.  
  2447. static int getnum()
  2448. {
  2449.     register int    i, c;
  2450.  
  2451.     while (isspace(c = getchar()))
  2452.         ;
  2453.     (void)ungetc(c, stdin);
  2454.     for (i = 0; isdigit(c = getchar()); )
  2455.         i = i * 10 + c - '0';
  2456.     (void)ungetc(c, stdin);
  2457.     return (i);
  2458. }
  2459.  
  2460. static int getint()
  2461. {
  2462.     register int    i;
  2463.     register char    c, flag = 0;
  2464.  
  2465.     while (isspace(c = getchar()))
  2466.         ;
  2467.     if (c == '-')
  2468.         flag = 1;
  2469.     else
  2470.         (void)ungetc(c, stdin);
  2471.     for (i = 0; isdigit(c = getchar()); )
  2472.         i = i * 10 + c - '0';
  2473.     (void)ungetc(c, stdin);
  2474.     return (flag ? -i : i);
  2475. }
  2476.  
  2477. static resolve_name(font, size, name, newmag)
  2478.     char        *name;
  2479.     int        font, size;
  2480.     double        *newmag;
  2481. {
  2482.     char        *index();
  2483.  
  2484.     *newmag = 1.0;
  2485.     (void)strcpy(name, fonts[font].int_name);
  2486.     if (size <= 10)
  2487.     {
  2488.         /* stop at first digit */
  2489.         for ( ; *name != '\0'; ++name)
  2490.             if (isdigit(*name))
  2491.                 break;
  2492.         /* overlay the size spec */
  2493.         (void)sprintf(name, "%d", size);
  2494.     }
  2495.     else switch (size)
  2496.     {
  2497.         case 11:
  2498.             *newmag = 1.095445;
  2499.             break;
  2500.         case 12:
  2501.             *newmag = 1.2;
  2502.             break;
  2503.         case 14:
  2504.             *newmag = 1.44;
  2505.             break;
  2506.         case 17:
  2507.             *newmag = 1.728;
  2508.             break;
  2509.         case 24:
  2510.         case 25:
  2511.             *newmag = 2.48832;
  2512.             break;
  2513.         default:
  2514.             (void)fprintf(stderr, "Can't handle point size %d\n",
  2515.                 size);
  2516.             break;
  2517.     }
  2518. }
  2519.  
  2520. static loadfont(font, sizeindex)
  2521.     int        font, sizeindex;
  2522. {
  2523.     register int    size    = pstab[sizeindex];
  2524.     double        newmag;
  2525.     char        fontfile[256];
  2526.  
  2527.     fontchanged = 0;
  2528.     /* defined yet? */
  2529.     if (fonts[font].texfont[sizeindex] < 0)
  2530.     {
  2531.         resolve_name(font, size, fontfile, &newmag);
  2532.         fnt_def(fontind, 0, (int)(newmag * (double)(size * (1<<16))),
  2533.             size * (1<<16), "", fontfile);
  2534.         fonttab[fontind].font = font;
  2535.         fonttab[fontind].size = size;
  2536.         fonts[font].texfont[sizeindex] = fontind++;
  2537.     }
  2538.     fnt_num(fonts[font].texfont[sizeindex]);
  2539. }
  2540.  
  2541. static outchar(ch)
  2542.     int        ch;
  2543. {
  2544.     register int    c, i, index, code, width;
  2545.     register fontdes    *f;
  2546.     register int    savedfont = -1;
  2547.  
  2548. #ifdef    DEBUG_OUTPUT
  2549.     (void)fprintf(stderr, "<%c>\n", ch);
  2550. #endif    DEBUG_OUTPUT
  2551.     c = ch - 32;
  2552.     f = &fonts[engine.s_font_num];
  2553.     index = f->fitab[c];                /* char to index */
  2554.     if (index != 0)
  2555.     {
  2556.         code = f->codetab[index];
  2557.         width = f->widtab[index];
  2558.     }
  2559.     else                        /* a special then */
  2560.     {
  2561.         for (i = 1; i <= dev.nfonts; ++i)
  2562.         {
  2563.             f = &fonts[i];
  2564.             if (!f->tfontp->specfont)
  2565.                 continue;
  2566.             if (f->fitab == 0)        /* font not available */
  2567.                 continue;
  2568.             if ((index = f->fitab[c]) != 0)
  2569.             {
  2570.                 savedfont = engine.s_font_num;
  2571.                 engine.s_font_num = i;
  2572.                 fontchanged = 1;
  2573.                 code = f->codetab[index];
  2574.                 width = f->widtab[index];
  2575.                 break;
  2576.             }
  2577.         }
  2578.     }
  2579.     if (index != 0)
  2580.     {
  2581.         if (fontchanged)
  2582.             loadfont(engine.s_font_num, engine.s_point_index);
  2583. /*
  2584. **    Rule height is roughly 1/18th of point size
  2585. */
  2586. #ifdef    USE_PUT
  2587.         if (code != RULE_CHAR)
  2588.             put_char(code);
  2589.         else
  2590.             put_rule(gtosp(engine.s_resolution *
  2591.             engine.s_point_size / (72 * 18)), gtosp(width));
  2592. #else
  2593.         if (code != RULE_CHAR)
  2594.             set_char(code);
  2595.         else
  2596.             set_rule(gtosp(engine.s_resolution *
  2597.             engine.s_point_size / (72 * 18)), gtosp(width));
  2598.         last_move += (width * engine.s_point_size + halfwidth) / dev.unitwidth;
  2599. #endif
  2600.         if (savedfont >= 0)
  2601.         {
  2602.             engine.s_font_num = savedfont;
  2603.             fontchanged = 1;
  2604.         }
  2605.     }
  2606.     else if (ch != ' ')        /* kludge, space glyph not in fonts */
  2607.         (void)fprintf(stderr, "Font %s, glyph %d not found\n",
  2608.             fonts[engine.s_font_num].font_name, ch);
  2609. }
  2610.  
  2611. static outstring(s)
  2612.     char        *s;
  2613. {
  2614.     register int    low, mid, high;
  2615.     register char    *t, *m;
  2616.  
  2617. #ifdef    DEBUG_OUTPUT
  2618.     (void)fprintf(stderr, "<%s>\n", s);
  2619. #endif    DEBUG_OUTPUT
  2620.     low = 0;
  2621.     high = dev.nchtab - 1;
  2622.     while (low <= high)
  2623.     {
  2624.         mid = (low + high) / 2;
  2625.         t = s;
  2626.         m = specialtab[mid].chname;
  2627.         while (*t == *m && *t != '\0')
  2628.             ++t, ++m;
  2629.         if (*t > *m)
  2630.             low = mid + 1;
  2631.         else if (*t < *m)
  2632.             high = mid - 1;
  2633.         else                /* equal, found it */
  2634.         {
  2635.             outchar(specialtab[mid].ordinal + 128);
  2636.             break;
  2637.         }
  2638.     }
  2639. }
  2640.  
  2641. static hmove(n)
  2642.     int        n;
  2643. {
  2644.     engine.s_H += n;
  2645.     if (n == last_move)
  2646.     {
  2647.         last_move = 0;
  2648.         return;
  2649.     }
  2650.     n -= last_move;
  2651.     last_move = 0;
  2652.     right(gtosp(n));
  2653. }
  2654.  
  2655. static hgoto(n)
  2656.     int        n;
  2657. {
  2658. #ifdef    USE_PUT
  2659.     engine.s_H += last_move;
  2660.     last_move = 0;
  2661.     if (n == engine.s_H)
  2662.         return;
  2663.     hmove(n - engine.s_H);
  2664. #else
  2665.     pop();
  2666.     push();
  2667.     down(gtosp(engine.s_V));
  2668.     right(gtosp(n));
  2669.     engine.s_H = n;
  2670.     last_move = 0;
  2671. #endif
  2672. }
  2673.  
  2674. static vgoto(n)
  2675.     int        n;
  2676. {
  2677.     if (n == engine.s_V)
  2678.         return;
  2679.     vmove(n - engine.s_V);
  2680. }
  2681.  
  2682. static specialchar()
  2683. {
  2684.     register char    c, *p;
  2685.     char        special[10];
  2686.  
  2687.     for (p = special; isprint(c = getchar()); )
  2688.         *p++ = c;
  2689.     *p = '\0';
  2690.     outstring(special);
  2691. }
  2692.  
  2693. static finishpage()
  2694. {
  2695.     /* finish previous page */
  2696.     if (bopsent)
  2697.     {
  2698.         pop();
  2699.         eop();
  2700.         ++engine.s_page_num;
  2701.     }
  2702.     bopsent = 0;
  2703. }
  2704.  
  2705. static newpage(n)
  2706. {
  2707.     finishpage();
  2708.     last_move = engine.s_H = engine.s_V = 0;
  2709.     counters[0] = n;
  2710.     back = bop(counters, back);
  2711.     /* DVI output origin is at (1in,1in), need to cancel */
  2712.     if (pageoffset)
  2713.     {
  2714.         down(-CPIN * FIX / 100);    /* up 1 in */
  2715.         right(-CPIN * FIX / 100);    /* left 1 in */
  2716.     }
  2717.     push();
  2718.     bopsent = 1;
  2719. }
  2720.  
  2721. static nextword()
  2722. {
  2723.     register int    c;
  2724.  
  2725.     while (!isspace(getchar()))
  2726.         ;
  2727.     while (isspace(c = getchar()))
  2728.         ;
  2729.     (void)ungetc(c, stdin);
  2730. }
  2731.  
  2732. static getstring(s, len)
  2733.     char        *s;
  2734.     int        len;
  2735. {
  2736.     register char    c;
  2737.  
  2738.     --len;                /* for the '\0' terminator */
  2739.     while (len > 0 && !isspace(c = getchar()))
  2740.         *s++ = c;
  2741.     *s = '\0';
  2742. }
  2743.  
  2744. /*
  2745. **    If you expect to load fonts above ditroff's limit of 10
  2746. **    you may need this routine.
  2747. */
  2748. static fontposition(i, s)
  2749.     int        i;
  2750.     char        *s;
  2751. {
  2752. }
  2753.  
  2754. static postamble()
  2755. {
  2756.     register int    i;
  2757.     double        newmag;
  2758.     char        fontfile[256];
  2759.  
  2760.     finishpage();        /* ship off pending page */
  2761.     /* we use one level of stack */
  2762.     post(back, NUM, DEN, mag, HEIGHT, WIDTH, 1, engine.s_page_num);
  2763.     for (i = 0; i < fontind; ++i)
  2764.     {
  2765.         register struct fonttab    *ft = &fonttab[i];
  2766.  
  2767.         resolve_name(ft->font, ft->size, fontfile, &newmag);
  2768.         fnt_def(i, 0, (int)(newmag * (double)(ft->size * (1<<16))),
  2769.             ft->size * (1<<16), "", fontfile);
  2770.     }
  2771.     post_post();
  2772. }
  2773.  
  2774. static setfontsize(n)
  2775.     int        n;
  2776. {
  2777.     register int    i;
  2778.  
  2779.     for (i = 0; i < dev.nsizes; ++i)
  2780.         if (pstab[i] == n)
  2781.             break;
  2782.     if (i >= dev.nsizes)
  2783.     {
  2784.         (void)fprintf(stderr, "%d is not a legal point size\n", n);
  2785.         return;
  2786.     }
  2787.     engine.s_point_size = n;
  2788.     engine.s_point_index = i;
  2789. }
  2790.  
  2791. static int devcntl()
  2792. {
  2793.     register char    c;
  2794.     register int    i;
  2795.     char        comment[256];
  2796.     char        fontname[256];
  2797.  
  2798.     while (isspace(c = getchar()))
  2799.         ;
  2800.     switch (c)
  2801.     {
  2802.     case 'i':            /* initialize */
  2803.         nextword();
  2804.         (void)sprintf(comment, "Generated by %s from ditroff output for %s at resolution %d",
  2805.             prog_name, engine.s_ts_name, engine.s_resolution);
  2806.         if (!readfontdir())
  2807.             fatal("Can't read DESC file\n");
  2808.         pre(NUM, DEN, mag, comment);
  2809.         break;
  2810.     case 'T':            /* typesetter name */
  2811.         nextword();
  2812.         getstring(engine.s_ts_name, sizeof(engine.s_ts_name));
  2813.         break;
  2814.     case 'r':            /* resolution */
  2815.         nextword();
  2816.         engine.s_resolution = getnum();
  2817.         if (engine.s_resolution <= 0)
  2818.             fatal("Resolution should be positve, is %d\n",
  2819.                 engine.s_resolution);
  2820.         scale = 72 * (1<<16) / engine.s_resolution;
  2821.         engine.s_horizontal = getnum();
  2822.         engine.s_vertical = getnum();
  2823.         break;
  2824.     case 'p':            /* pause */
  2825.         break;
  2826.     case 's':            /* stop */
  2827.         nextword();
  2828.         postamble();
  2829.         return(1);
  2830.     case 't':            /* trailer */
  2831.         nextword();
  2832.         break;
  2833.     case 'f':            /* associate font with number */
  2834.         nextword();
  2835.         i = getnum();
  2836.         nextword();
  2837.         getstring(fontname, sizeof(fontname));
  2838.         fontposition(i, fontname);
  2839.         break;
  2840.     case 'H':            /* set character height */
  2841.         break;
  2842.     case 'S':            /* set slant */
  2843.         break;
  2844.     default:
  2845.         fatal("Unknown device control %c\n", c);
  2846.         break;
  2847.     }
  2848.     return (0);
  2849. }
  2850.  
  2851. static graphics()
  2852. /*
  2853. **    Conversion to tpic output left as an exercise for hacker.
  2854. **    Should generate xxx commands in DVI.
  2855. */
  2856. {
  2857.     register char    c;
  2858.     register int    p1, p2, p3;
  2859.  
  2860.     switch (c = getchar())
  2861.     {
  2862.     case 'l':
  2863.         break;
  2864.     case 'c':
  2865.         break;
  2866.     case 'e':
  2867.         break;
  2868.     case 'a':
  2869.         break;
  2870.     case '~':
  2871.         break;
  2872.     default:
  2873.         fatal("Unknown drawing function %c\n", c);
  2874.         break;
  2875.     }
  2876.     /* eat up the rest of the line */
  2877.     while (getchar() != '\n')
  2878.         ;
  2879. }
  2880.  
  2881. reader()
  2882. /*
  2883. **    Switch to appropriate routine depending on character read in
  2884. */
  2885. {
  2886.     register int    c;
  2887.  
  2888.     while ((c = getchar()) != EOF)
  2889.     {
  2890. #ifdef    DEBUG_INPUT
  2891.         (void)fprintf(stderr, "%c", c);
  2892. #endif    DEBUG_INPUT
  2893. /*
  2894. **    The code generated by pcc for switch statements is sufficiently
  2895. **    inefficient to take out the most common cases. (Loop to match, gag!)
  2896. */
  2897.         if (c == 'h')
  2898.         /* this is used often enough to justify making it inline
  2899.         instead of calling getnum */
  2900.         {
  2901.             register int    hmotion;
  2902.  
  2903.             for (hmotion = 0; isdigit(c = getchar()); )
  2904.                 hmotion = hmotion * 10 + c - '0';
  2905.             (void)ungetc(c, stdin);
  2906.             hmove(hmotion);
  2907.         }
  2908.         else if (c == 'c')
  2909.             outchar(getchar());
  2910.         else if (isdigit(c))
  2911.         {
  2912.             register int    hmotion;
  2913.             register char    c1;
  2914.  
  2915.             if (!isdigit(c1 = getchar()))
  2916.             {
  2917.                 fatal("Non-digit in nn\n");
  2918.                 return;
  2919.             }
  2920.             hmotion = (c - '0') * 10 + c1 - '0';
  2921.             hmove(hmotion);
  2922.             outchar(getchar());
  2923.         }
  2924.         /* for the less common cases we can afford some inefficiency */
  2925.         else switch (c)
  2926.         {
  2927.         case 'H':
  2928.             hgoto(getnum());
  2929.             break;
  2930.         case 'v':
  2931.             vmove(getnum());
  2932.             break;
  2933.         case 'V':
  2934.             vgoto(getint());
  2935.             break;
  2936.         case 'C':
  2937.             specialchar();
  2938.             break;
  2939.         case 's':
  2940.             setfontsize(getnum());
  2941.             fontchanged = 1;
  2942.             break;
  2943.         case 'f':
  2944.             engine.s_font_num = getnum();
  2945.             engine.s_font_name = fonts[engine.s_font_num].font_name;
  2946.             fontchanged = 1;
  2947.             break;
  2948.         case 'p':
  2949.             newpage(getnum());
  2950.             break;
  2951.         case 'n':
  2952.             (void)getnum();        /* no action required */
  2953.             (void)getnum();
  2954.             break;
  2955.         case 'w':
  2956.             break;            /* no action required */
  2957.         case 'x':
  2958.             if (devcntl())        /* stop? */
  2959.                 return;
  2960.             break;
  2961.         case 'D':
  2962.             graphics();
  2963.             break;
  2964.         case '\0':            /* discard whitespace and noise */
  2965.         case ' ':
  2966.         case '\n':
  2967.             break;
  2968.         default:
  2969.             fatal("Unrecognized ditroff command: %c\n", c);
  2970.             break;
  2971.         }
  2972.     }
  2973. }
  2974. SHAR_EOF
  2975. if test 10736 -ne "`wc -c 'reader.c'`"
  2976. then
  2977.     echo shar: error transmitting "'reader.c'" '(should have been 10736 characters)'
  2978. fi
  2979. echo shar: extracting "'tfm2desc.1'" '(2653 characters)'
  2980. if test -f 'tfm2desc.1'
  2981. then
  2982.     echo shar: over-writing existing file "'tfm2desc.1'"
  2983. fi
  2984. cat << \SHAR_EOF > 'tfm2desc.1'
  2985. .TH TFM2DESC 1 4/9/88
  2986. .CM 1
  2987. .SH "NAME"
  2988. tfm2desc \- generate ditroff font description file from TeX tfm file
  2989. .SH "SYNOPSIS"
  2990. tfm2desc [\fB\-ddesignsize\fP] [\fB\-sspacewidth\fP] \fItfmprefix\fP [type]
  2991. .SH "DESCRIPTION"
  2992. \fITfm2desc\fP is a program to generate typesetter description
  2993. files from tfm files.
  2994. The typesetter being described is a virtual one, since the DESC
  2995. file will be used with \fIditroff\fP and \fIditdvi\fP.
  2996. .PP
  2997. The file argument is the name of a file in the current directory
  2998. with the following data: The first line is the name of the \fIditroff\fP
  2999. font, e.g.
  3000. R.
  3001. Each succeeding lines describes one character.
  3002. The line contains the octal code and the one- or
  3003. two character sequence for the glyph, separated by a tab.
  3004. Adjacent duplicate octal codes can be used to specify characters
  3005. with one or more synonyms and will generate ``ditto'' lines in
  3006. the output file.
  3007. .PP
  3008. \fItfm2desc\fP reads the tfm file named TEXFONT/tfmprefix.tfm.
  3009. TEXFONT is a #define'd string in the source you can change.
  3010. The metrics go to standard output. These should go to a file
  3011. of the same name as the first line of the input file.
  3012. The output should then be processed by \fImakedev\fP.
  3013. .PP
  3014. The \fB\-d\fP flag specifies an alternate design size instead of
  3015. that in the tfm file.
  3016. All widths will be scaled accordingly.
  3017. This allows you to make the widths as large as possible but they should be
  3018. less than 256 (the limit imposed by \fIditroff\fP).
  3019. Large width entries minimize the roundoff error in the widths.
  3020. The design size will be written on the unitwidth line in the output file.
  3021. .PP
  3022. The \fB\-s\fP flag specifies the spacewidth line in the output file.
  3023. .PP
  3024. \fItype\fP is an optional single letter which is either m or s, meaning
  3025. monospaced or special (\fIditroff\fP terminology).
  3026. No ligature entries will be generated for these fonts.
  3027. The special line will be put in the output file for special fonts.
  3028. .PP
  3029. The #define'd constant RESOLUTION should match that in the DESC file.
  3030. Since the printer is imaginary, the choice is arbitrary, subject
  3031. to constraints imposed on the unitwidth and width entries.
  3032. As distributed, 576 units per inch is used.
  3033. .SH "FILES"
  3034. /usr/lib/tex/fonts directory where the tfm files live
  3035. .SH "SEE ALSO"
  3036. ditroff(1), makedev(1), ditdvi(1)
  3037. .SH "DIAGNOSTICS"
  3038. Hopefully self-explanatory.
  3039. .SH "BUGS"
  3040. Contains hacks to deal with the 1/6 and 1/12 em spacing characters
  3041. and the baseline rule.
  3042. These should be placed in positions 128 and
  3043. above because all the lower 128 positions are occupied in TeX fonts.
  3044. \fIDitdvi\fP knows about this hack.
  3045. .SH "ACKNOWLEDGEMENT"
  3046. This program borrows ideas and some code from \fItfm2difont\fP,
  3047. written by Scott Simpson.
  3048. SHAR_EOF
  3049. if test 2653 -ne "`wc -c 'tfm2desc.1'`"
  3050. then
  3051.     echo shar: error transmitting "'tfm2desc.1'" '(should have been 2653 characters)'
  3052. fi
  3053. echo shar: extracting "'tfm2desc.c'" '(6358 characters)'
  3054. if test -f 'tfm2desc.c'
  3055. then
  3056.     echo shar: over-writing existing file "'tfm2desc.c'"
  3057. fi
  3058. cat << \SHAR_EOF > 'tfm2desc.c'
  3059. #include    <stdio.h>
  3060.  
  3061. /*
  3062. **    Get character widths out of tfm files. See man page.
  3063. */
  3064.  
  3065. /* where the TeX tfm files live */
  3066. #ifndef        TEXFONT
  3067. #define        TEXFONT        "/usr/lib/tex/fonts/"
  3068. #endif
  3069.  
  3070. #define        FIX        (1<<20)
  3071. #define        UNKNOWN        (-1)
  3072. #define        PPI        72
  3073.  
  3074. #ifndef        RESOLUTION
  3075. #define        RESOLUTION    (PPI*8)
  3076. #endif
  3077.  
  3078. #define        HEADERSIZE    24
  3079.  
  3080. int        designsize    = 0;
  3081. int        spacewidth    = -1;
  3082.  
  3083. usage()
  3084. {
  3085.     (void)fprintf(stderr, "Usage: tfm2desc [-d<ds>] [-s<sw>] fontmap [m|s]\n");
  3086.     exit(1);
  3087. }
  3088.  
  3089. main(argc,argv)
  3090.     int        argc;
  3091.     char        *argv[];
  3092. {
  3093.     register int    c;
  3094.     register char    type = ' ';
  3095.     char        tfmname[256];
  3096.     char        extname[10];
  3097.     FILE        *tfmfile;
  3098.     extern int    optind;
  3099.     extern char    *optarg;
  3100.     int        getopt(), atoi();
  3101.  
  3102.     while ((c = getopt(argc, argv, "d:s:")) != EOF)
  3103.     {
  3104.         switch (c)
  3105.         {
  3106.         case 'd':
  3107.             designsize = atoi(optarg);
  3108.             if (designsize <= 0)
  3109.                 (void)fprintf(stderr, "Bad designsize: %d, will use designsize in tfm file\n", designsize);
  3110.             break;
  3111.         case 's':
  3112.             spacewidth = atoi(optarg);
  3113.             break;
  3114.         default:
  3115.             exit(1);
  3116.             break;
  3117.         }
  3118.     }
  3119.  
  3120.     argc -= optind;
  3121.     argv += optind;
  3122.  
  3123.     if (argc < 1)
  3124.         usage();
  3125.     if (freopen(argv[0], "r", stdin) == NULL)
  3126.     {
  3127.         perror(argv[0]);
  3128.         exit(1);
  3129.     }
  3130.     (void)sprintf(tfmname, "%s%s.tfm", TEXFONT, argv[0]);
  3131.     if ((tfmfile = fopen(tfmname, "r")) == NULL)
  3132.     {
  3133.         perror(argv[0]);
  3134.         exit(1);
  3135.     }
  3136.     (void)fgets(extname, sizeof(extname), stdin);
  3137.     if (extname[1] == '\n')
  3138.         extname[1] = '\0';
  3139.     if (extname[2] == '\n')
  3140.         extname[2] = '\0';
  3141.     if (argc >= 2)
  3142.         type = argv[1][0];
  3143.     convert(extname, argv[0], tfmfile, type);
  3144.     exit(0);
  3145. }
  3146.  
  3147. #define    get1(buffer, offset)    (buffer[offset])
  3148.  
  3149. int get2(buffer, offset)
  3150.     unsigned char    *buffer;
  3151.     int        offset;
  3152. {
  3153.     return ((buffer[offset] << 8) | buffer[offset + 1]);
  3154. }
  3155.  
  3156. int get4(buffer, offset)
  3157.     unsigned char    *buffer;
  3158.     int    offset;
  3159. {
  3160.     register int    i, n;
  3161.  
  3162.     n = 0;
  3163.     for (i = 0; i < 4; ++i)
  3164.         n = (n << 8) | buffer[offset + i];
  3165.     return (n);
  3166. }
  3167.  
  3168. /*
  3169. **    Convert from FIXES to pixels. The roundoff error of this
  3170. **    routine is a max of (72*designsize)/2^20, which is negligible
  3171. **    for ordinary pointsizes.
  3172. */
  3173. fixestopixels(fix, designsize)
  3174.     int        fix;
  3175.     int        designsize;
  3176. {
  3177.     register unsigned long    l;
  3178.  
  3179.     l = fix * RESOLUTION / PPI;
  3180.     l = (l * designsize + FIX / 2) / FIX;
  3181.     return (l);
  3182. }
  3183.  
  3184. /*
  3185. **    The main routine which converts a tfm file to a troff width table file
  3186. */
  3187. convert(extname, intname, tfmfile, type)
  3188.     char        *extname, *intname;
  3189.     FILE        *tfmfile;
  3190.     char        type;
  3191. {
  3192.     register int    i, j, ch;
  3193.     register unsigned char    *tfmbuf;
  3194.     register int    aheight;
  3195.     int        lh, bc, ec, nw, nh;
  3196.     char        line[256];
  3197.     char        name[3];
  3198.     char        *malloc();
  3199.  
  3200. /*
  3201. **    Read the whole tfm file in one gulp
  3202. */
  3203.     i = getc(tfmfile) & 0xff;
  3204.     i = (i << 8) | (getc(tfmfile) & 0xff);
  3205.     i *= 4;
  3206.     if ((tfmbuf = (unsigned char *)malloc(i)) == NULL)
  3207.     {
  3208.         (void)fprintf(stderr, "Out of memory\n");
  3209.         exit(1);
  3210.     }
  3211.     i -= 2;
  3212.     if ((j = fread(tfmbuf + 2, sizeof(char), i, tfmfile)) != i)
  3213.     {
  3214.         (void)fprintf(stderr, "Short read on %s, want %d, got %d\n",
  3215.             intname, i, j);
  3216.         exit(1);
  3217.     }
  3218.  
  3219.     (void)printf("name %s\ninternalname %s\n", extname, intname);
  3220.     if (type == 's')
  3221.         (void)printf("special\n");
  3222.     else if (type != 's' && type != 'm')    /* not special or mono-spaced */
  3223.         (void)printf("ligatures ff fi fl ffi ffl 0\n");
  3224.     if (type != 's')
  3225.     {
  3226.         if ((aheight = getaheight(tfmbuf)) == UNKNOWN)
  3227.         {
  3228.             (void)fprintf(stderr, "No letter 'a' in %s.tfm\n", intname);
  3229.             (void)fprintf(stderr, "\tSetting height to zero\n");
  3230.             aheight = 0;
  3231.         }
  3232.     }
  3233.  
  3234.     if (spacewidth >= 0)
  3235.         (void)printf("spacewidth %d\n", spacewidth);
  3236.  
  3237.     lh = get2(tfmbuf, 2) * 4;
  3238.     bc = get2(tfmbuf, 4);
  3239.     ec = get2(tfmbuf, 6);
  3240.     nw = get2(tfmbuf, 8) * 4;
  3241.     nh = get2(tfmbuf, 10) * 4;
  3242.     if (designsize <= 0)
  3243.         designsize = get4(tfmbuf, HEADERSIZE + 4) / FIX;
  3244.  
  3245.     (void)printf("charset\n");
  3246.     ch = -1;
  3247.     while (fgets(line, sizeof(line), stdin) != NULL)
  3248.     {
  3249.         register int    widthindex, heightanddepth, width;
  3250.         int        height, depth, kerning;
  3251.         int        temp;
  3252.  
  3253.         if (sscanf(line, "%o\t%2s\n", &temp, name) != 2)
  3254.         {
  3255.             (void)fprintf(stderr, "Bad spec file: %s", line);
  3256.             exit(1);
  3257.         }
  3258.         /* space is a terminator */
  3259.         if (name[0] == '\0')
  3260.         {
  3261.             name[0] = ' ';
  3262.             name[1] = '\0';
  3263.         }
  3264.         if (temp >= 128)
  3265.         {
  3266.             specials(name, temp, spacewidth);
  3267.             continue;
  3268.         }
  3269.         if (temp == ch)
  3270.         {
  3271.             (void)printf("%s\t\"\n", name);
  3272.             continue;
  3273.         }
  3274.         ch = temp;
  3275.         widthindex = get1(tfmbuf, HEADERSIZE + lh + (ch-bc)*4);
  3276.         heightanddepth = get1(tfmbuf, HEADERSIZE + lh + (ch-bc)*4 + 1);
  3277.         if (widthindex == 0)
  3278.             continue;
  3279.         width = get4(tfmbuf, HEADERSIZE + lh + (ec-bc+1)*4 + widthindex*4);
  3280.         width = fixestopixels(width, designsize);
  3281.         height = get4(tfmbuf, HEADERSIZE + lh + (ec-bc+1)*4 + nw +
  3282.                 (heightanddepth>>4)*4);
  3283.         height = fixestopixels(height, designsize);
  3284.         depth = get4(tfmbuf, HEADERSIZE + lh + (ec-bc+1)*4 + nw + nh +
  3285.             (heightanddepth & 0xf)*4);
  3286.         depth = fixestopixels(depth, designsize);
  3287.         kerning = 0;
  3288.         if (height > aheight)
  3289.             kerning |= 2;
  3290.         if (depth > 0)
  3291.             kerning |= 1;
  3292.         if (width >= 256)
  3293.             (void)fprintf(stderr, "Warning: width of %d for %s is too wide for ditroff to handle\n",
  3294.                 width, name);
  3295.         (void)printf("%s\t%d\t%d\t0%o\n", name, width, kerning, ch);
  3296.     }
  3297. }
  3298.  
  3299. /* Returns the height of the letter 'a' in the font passed as a parameter.
  3300.  * The height is returned in pixels since troff likes to use pixels as its
  3301.  * unit. If the letter 'a' is not found, UNKNOWN is returned.
  3302.  */
  3303. int getaheight(buffer)
  3304.     unsigned char    *buffer;
  3305. {
  3306.     register int    lh, bc, ec, nw, designsize;
  3307.     register int    widthindex, heightanddepth, height;
  3308.  
  3309.     lh = get2(buffer, 2) * 4;
  3310.     bc = get2(buffer, 4);
  3311.     ec = get2(buffer, 6);
  3312.     nw = get2(buffer, 8) * 4;
  3313.     if (bc > 'a' || ec < 'a')
  3314.         return (UNKNOWN);
  3315.     designsize = get4(buffer, HEADERSIZE + 4) / FIX;    /* Convert from FIXes */
  3316.     widthindex = get1(buffer, HEADERSIZE + lh + ('a'-bc)*4);
  3317.     heightanddepth = get1(buffer, HEADERSIZE + lh + ('a'-bc)*4 + 1);
  3318.     if (widthindex == 0)
  3319.         return (UNKNOWN);
  3320.     height = get4(buffer, HEADERSIZE + lh + (ec-bc+1)*4 + nw +
  3321.         (heightanddepth >> 4)*4);
  3322.     return (fixestopixels(height, designsize));
  3323. }
  3324.  
  3325. specials(name, ch, width)
  3326.     char        *name;
  3327.     int        ch, width;
  3328. {
  3329.     if (strcmp(name, "\\&") == 0)
  3330.         width = 0;
  3331.     /* assume em space is twice space width */
  3332.     else if (strcmp(name, "\\^") == 0)
  3333.         width = (width + 3) / 6;        /* 1/12 em space */
  3334.     else if (strcmp(name, "\\|") == 0)
  3335.         width = (width + 1) / 3;        /* 1/6 em space */
  3336.     /* make ru same as spacewidth */
  3337.     (void)printf("%s\t%d\t0\t0%o\n", name, width, ch);
  3338. }
  3339. SHAR_EOF
  3340. if test 6358 -ne "`wc -c 'tfm2desc.c'`"
  3341. then
  3342.     echo shar: error transmitting "'tfm2desc.c'" '(should have been 6358 characters)'
  3343. fi
  3344. #    End of shell archive
  3345. exit 0
  3346.